Thursday, March 3, 2011

Dynamic parameter Passing in Message mapping








Message Mapping, enter constant as fallows(Dynamically passing)


2) Go to Signature tab in message mapping specify the parameter as fallows


3) in this below case, there are 5 types values, we want to pass each value at different instances as fallows


4) now see the transformation step and assign constant parameter as import parameter to Interface mapping. in certain cases , we can also put export parameter. i.e. getting value from mapping to Bpm runtime.




In interface mapping , parameter binding as fallows.






Different Interface mapping details based on different value in input parameter




How to use export parameter in Mapping

think message mapping as UDF, import and export parameters are the input and output parameters for the mapping.

the above is telling about how to use the import variables in message mapping. but how do we export the values to variables which are defined in signature tab.
-------------------------------------------------------------------------------------------------

Defining and Using Export Parameters Locate the document in its SAP Library structure

Use

You want to use the transformation step and the export parameters of a user-defined function to transfer values to an integration or monitoring process at runtime

See also: Parameterized Message Mappings.

Prerequisites

You have loaded a source and a target structure to the mapping editor and are in change mode.

Procedure

...

1. In the mapping editor, switch to the Signature tab page. Enter export parameters in the table for all functions that are to transfer values to a transformation step at runtime. Note that you cannot enter the same export parameters for multiple functions.

2. Export parameters are not included in the signature of user-defined functions. They set their export parameters directly in the source text of the user-defined function:


if (exists(“MY_STR_PAR”) == true
&& exists(“MY_INT_PAR”) == true
&& exists(“MY_OBJ_PAR”) == true)

{
getOutputParameters.setString(
“MY_STR_PAR”,
[value of type java.lang.String]);

getOutputParameters.setInt(
“MY_INT_PAR”,
[value of type int]);

getOutputParameters.setValue(
“MY_OBJ_PAR”,
[value of type java.lang.Object]);
}



The names of the export parameters that you set in the source text must be identical to the names of the message mapping export parameters on the Signature tab page (not case-sensitive).Caution

3. Save your message mapping.

To use your message mapping at configuration time, you must assign it to an appropriate operation mapping and connect the message mapping parameters to the operation mapping parameters:

4. If an appropriate operation mapping does not already exist, create one. Reference the operations that belong to the operation mapping and reference your parameterized message mapping (see: Operation Mapping).

5. To create the necessary operation mapping parameters, choose Parameters. Note that multiple message mapping export parameters cannot be connected to the same operation mapping export parameters.

6. In the Binding column in the table in frame Mapping Programs, there is a button for defining a binding (This graphic is explained in the accompanying text). Choose the button in the row in which your message mapping program is entered.

7. Assign interface mapping export parameters to the operation mapping export parameters.

8. Save your operation mapping.

Result

Once you have activated your operation mapping, you can access the export parameters in an integration or monitoring process (see: Transformation Step).

------------------------------------------------------------------------------------------------------------------------------------------------------------------









Look Up in Mapping, parsing xml structure in mapping


Working Lookup and Parsing xml Structure in UDF
Topics covered in this blog
  • Lookup
  • Parsing xml structure in mapping ,In UDF
  • Using communication channel in Lookup( In mapping)
  • Executing Lookup.

i) Create a communication channel ,that we are going to use in LookUP.

Ex: Soap communication channel

ii) Create UDF( here we need to pass the input parameters and communication channel details)

in this example ,

communication channel as fallows








Source xml and Target xml schema as fallows in the mapping



UDF is used to get discount value


Creating UDF and input parameters as fallows

Java code content for the UDF as fallows

Testing Mapping and procedure to test


Sample Input data and test results after execution of mapping


The Important thing is " the way to enter xml structure to communication channel and parsing specific parameter from response xml payload."

Source Code of the UDF as fallows

public String calculateDiscount(String cust_no, String region, Channel
soapDiscount, Container container) throws StreamTransformationException{
SystemAccessor accessor = null;
String discount = "";
StringBuffer sb = new StringBuffer();
try{
// 1. Get a system accessor for the channel.
accessor = LookupService.getSystemAccessor(soapDiscount);

// 2. Build up request
InputStream reqStream;
String reqString =""
+ ""
+ ""
+ ""+cust_no+" "+region+""
+ "0 "
+ "";
reqStream = (InputStream) new
ByteArrayInputStream(reqString.getBytes());
XmlPayload reqPayload = LookupService.getXmlPayload(reqStream);

// 3. Call BRM
XmlPayload resPayload = (XmlPayload)accessor.call(reqPayload);

// 4. Parse result
byte[] b = new byte[4096];
for (int n; (n = resPayload.getContent().read(b)) != -1;) {
sb.append(new String(b, 0, n));
{
int i =sb.indexOf("") + 10;
int j =sb.indexOf("");
discount = sb.substring(i, j);
{
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
{
finally {

// 5. Close the accessor in order to free resources.
if (accessor!=null) accessor.close();
{
return discount;

/* same thing as opening database connection and closing database connection in jdbc- java*/

For more information
see the sdn.sap article at

Use full java links



Useful java code

Reading Text from a File

try {     BufferedReader in = new BufferedReader(new FileReader("infilename"));     String str;     while ((str = in.readLine()) != null) {         process(str);     }     in.close(); } catch (IOException e) { }