Hi all

This blog should give you some examples how the graphical mapping can be done without bad results.

This is only a proposal and my experience, this should not mean that there is no other solution.

But maybe it is helpful for some PI developer without SAP Mapping Training or deep experience.

We all know that the graphical tool looks very easy.

But to get a waterproof mapping and not only a LuckyPunch success you really need to know how it works.

I think and know

  • 99,9% of all mappings can be done by using graphical mapping tool
  • If you know how the target queue must look like then you can start with development
  • All other approach is trail & error with LuckyPunch result

Below you will find a summary of the most needed actions from my point of view.
(…and in this blog you can copy and paste the UDF code… )

IF Function

It looks easy but I saw a lot of garbage in the past.

So please notice: the two input “Queues” must have same number of values and same structure (ContextChanges). If not you have to think about this.
Maybe “MapWithDefault” or change Context can help!

SAP XI/PI/PO Mapping tricks and UDF samples

Target Element should only appear one time but source element is multiple.

Most solutions I saw have used CopyValue[0] or “RemoveContext” in combination “CollapsContext”.

Please be care full by using these 3 functions. I like to use “sum” for this.

SAP XI/PI/PO Mapping tricks and UDF samples

equalS vs. FixFalue

Sometimes a FixValue Table is better than equalS
SAP XI/PI/PO Mapping tricks and UDF samples

How to combine different hierarchies or levels (useOneAsMany and formatByExample)

Sometimes the target structure has 3 Elements which are relevant for one target field.

Sample: If qualifier of each position has value XY then value the Text of sub segment should be used.

(all of us know TDLINE Problems)
SAP XI/PI/PO Mapping tricks and UDF samples

SAP XI/PI/PO Mapping tricks and UDF samples

UDF: GetSystemname and SetFileName
SAP XI/PI/PO Mapping tricks and UDF samples

String sysName = “EMPTY”;

try{

sysName = (String) System.getProperty(“SAPSYSTEMNAME”);

}catch(Exception e) {

sysName = “ERROR”;

}

return sysName;

SAP XI/PI/PO Mapping tricks and UDF samples

String filename = new String(“EMPTY”);

DynamicConfiguration conf1 = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION); DynamicConfigurationKey key1 = DynamicConfigurationKey.create(“http:/”+”/sap.com/xi/XI/System/File”,”FileName”);

filename = var1;

try{

conf1.put(key1,filename);

}catch(Exception e) {

 

}

return filename;

 

UDF: how to handle SUPPRESS and CC
SAP XI/PI/PO Mapping tricks and UDF samples

try{

for ( int i = 0; i <  var1.length; i++){

if( var1[i].equals(ResultList.CC)){

result.addValue(“found CC”);

}else{

if( var1[i].equals(ResultList.SUPPRESS)){

result.addValue(“found SUPPRESS”);

}else{

result.addValue(var1[i]);

}//end els

}//end else

}//end for

 

//below how to set SUPPRESS und CC in UDF

//result.addSuppress();

//result.addContextChange();

 

}catch(Exception e) {

result.addValue(“EMPTY”);

}//end try

UDF: how to put all values of one CC into one target field (concat)
SAP XI/PI/PO Mapping tricks and UDF samples

String stringle = “”;

try{

for ( int i = 0; i <  var1.length; i++){

if(! var1[i].equals(ResultList.CC)){

stringle = stringle + var1[i];

}//end if

}//end for

result.addValue(stringle);

}catch(Exception e) {

result.addValue(“EMPTY”);

}//end try

 

UDF: to convert number to decimal

String in = var1.trim();

 

try {

double value = Double.parseDouble(in);

value = value / 1000d;

 

String res = new String (new java.text.DecimalFormat(“0.000”).format(value));

if (res.length() > 11)

res = res.substring(0, 11);

return (res);

 

} catch (NumberFormatException e) {

return (“ERROR ” + e.toString());

}

UDF: check if number. (the format number PI function throws errors, so this function helps to avoid mapping error)

SAP XI/PI/PO Mapping tricks and UDF samples

String ret;

int i = 0;

ret = “false”;

 

try{

i = Integer.valueOf(var1).intValue();

ret = “true”;

 

}catch ( Exception e){

ret = “false”;

}

 

return ret;

 

UDF: channelJump during mapping (asy)

SAP XI/PI/PO Mapping tricks and UDF samples

MappingTrace trace;

trace = container.getTrace();

 

String back=”default”;

 

try{

back = “start”;

//instance the channel to invoke the service.

Channel channel = LookupService.getChannel(“”,BS,CC);

SystemAccessor accessor = LookupService.getSystemAccessor(channel);

//payload xml

InputStream inputStream =new ByteArrayInputStream(payload.getBytes());

XmlPayload xmlpayload = LookupService.getXmlPayload(inputStream);

Payload SOAPOutPayload = null;

//The response will be a Payload. Parse this to get the response field out.

SOAPOutPayload = accessor.call(xmlpayload);

 

/* Parse the SOAPPayload to get the SOAP Response back.

The conversion rate is available under the Field Name ConversionRateResult */

InputStream inp = SOAPOutPayload.getContent();

back = “ende”;

 

} catch(Exception ex) {

trace.addWarning(ex.getMessage());

back = “ERROR”;

}

return back;

 

 

New NetWeaver Information at SAP.com

Very Helpfull

User Rating: Be the first one !