Thursday, October 24, 2013

Frequent UDF codes and mapping examples are used in PI system

Calling ASMA ( Adapter specific message attributes) in mapping, after enabling check boxes in adapter level.

choose your require attributes as shown in below( FileName, direcotry).






Use formatNumber , when you expect target number always in specific/fixed format/fixed length



Mapping mutiple items from sender to receiver.  E1EDL24 occurs from sender multiple times from sender, under this-> subelement. which is quanity, we need to check if the quanity more than one or not, we need to create target item's, whose items has quanity more than zero.






Substring from start index to Given number



In case, if you want to use multiple conditions, replace those multiple conditions with help fix-values standard function in-front of standard functions.

Dynamic configuration or variable substitution or Dynamic configuration Bean?
http://scn.sap.com/community/pi-and-soa-middleware/blog/2009/03/26/dynamic-configuration-vs-variable-substitution--the-ultimate-battle-for-the-file-name


SAP Help: how to use Message mapping and advanced mapping techniques
http://help.sap.com/saphelp_nw73/helpdata/en/fa/d59f9d241d4d59b75fa571481381ca/content.htm?frameset=/en/12/6000fa78414534816e251ca53a1702/frameset.htm

Very userfull mapping logics from stefangrube blog




Use one as many with example:


SAP Help Messages-mapping examples

UseOneAsMany for converting deep structure to Falt structure


sender(header, items)->receiver(flat structure, items(merging header information))

Below example: Each person has many telephone numbers, sender person table maintains id's name's, 2nd table, only for id's and telephone,    For target, we need to put data based on telephone.(need to repeat id,name by telephone number)

Logic explanation: 
id, Name array length is same(1st table),we need to fetch person name by using person id(need to compare with id in 2nd table),

First using HashMap-> create mapping table for personId,TelephoneNumber;  for every value from 2nd table (personID)





By willian LI
http://scn.sap.com/people/jin.shin/blog/2008/01/11/sap-pi-71-mapping-enhancements-series-mapping-enhancements-demo

Graphical variables, parametrized mapping, graphical looks, structural inconsistency, Functional libraries, importing structure from database.


stefangrube frequently used mapping functions:
http://scn.sap.com/people/stefan.grube/blog/2005/12/29/new-functions-in-the-graphical-mapping-tool-xi-30-sp13

Examples on MapwithDefault,  FormatByExample, sort, sortByKey, Index

Stefangrub's examples: suppress logic




Supress values in array:




SubString examples, Using indexOf




idoc 2 flatfile ( mapping scenarios)
picking when qualifier has xyz values, then ping another element at same level( some times this has empty, need to replace with empty)



Take IDTNR ,when qualifer =010; some times IDTNR has null values, in that case use empty field to map target filed
Handling Null values from source, replacing those with empty value,
MapwithDefault node function( its draw back, It is not properly working when source filed context is at upper level. So we need to maintain the context as it is, use mapwithdefault function as shown below
Format by examples helps to gets its previous context level





Substring for last N digitis





/* var1=var1.trim();
int Strlength =var1.length();
char  a;
boolean b;
if(Strlength>0)
{
 a = var1.charAt(Strlength-1);
 b = Character.isLetterOrDigit(a); 
if(!b)
return var1.substring(0,Strlength-1);
else 
return var1;
}
else
return var1; */

Frequent sap examples on mapping.


split string and integer

http://www.tutorialspoint.com/compile_java_online.php


public class HelloWorld{

     public static void main(String []args){
         int j =0;
         String s = "xyz123";
         
for(int i = 0; i < s.length(); i++)
{
   char c = s.charAt(i);j=i;
if(Character.isDigit(c))
       // System.out.println("Hello digit"+c);
       break;
      //  else
    //     System.out.println("Hello char"+c);
        
     //end if
}// end for

System.out.println("charat--->"+s.substring(0,j));
System.out.println("charat-->"+s.substring(j,s.length()));
}
    
    
}








Useful information From other blogs
------------------------
copyXML( no need of sub elements in structure) and structure inconsistancy and graphical variables usage(avoid global variables)




Creating Database structure from communication channel (no need of creation of target element)










Handling fault messages in RFC response , which are arrived from soap fault messages or rest.