on 06-11-2013 8:01 AM
Dear All,
From Source i had a field 'SOURCE' and target side,there are two fields 'TARGETA' & 'TARGETB'
Now my requirement is,from source side the values comes like
:61:1303080308AF62942,N001NBN130670017//XX1362745739190
0001051/052013XXX/O1/
:61:1303080308AF92705,XXXXREF//001XXXX130670022
XXXXXXXREF00004198/052013
:61:1303080308BF111531,X001XXXX130670016//XX1362746022195
0001418/052013XXX/O1
:61:1303080308BF145868,X001XXXX130670016//XX1362746022195
0001418/052013XXX/O1
In the source value the fields which contains A after the date,then it should go to 'TARGETA' with total value i.e after F,if B comes means it should go to 'TARGETB' with all total value.
for e.g
in the above fields,we have two fields with A, so the total value 62942+92705=155647 should go to the TARGETA
similarly the with B, 111531+145868=257399.
for this how can we write UDF,please suggest me.
thanks & regards
Hi Raj,
you can try this UDF
public void sumTotal(String[] a,String Type[], ResultList result,Container container)
{
String sumA="",sumB="";
int i,indexOfF,totalA=0,totalB=0;
for(i=0;i<a.length;++i)
{
indexOfF=a[i].indexOf('F');
if(indexOfF>0)
{
if(a[i].charAt(indexOfF-1)=='A')
{
sumA=a[i].substring(indexOfF+1,a[i].indexOf(','));
totalA=totalA+ Integer.parseInt(sumA);
}
}
if(indexOfF>0)
{
if(a[i].charAt(indexOfF-1)=='B')
{
sumB=a[i].substring(indexOfF+1,a[i].indexOf(','));
totalB=totalB+ Integer.parseInt(sumB);
}
}
}
if(Type[0].equals("A"))
{
result.addValue(""+totalA);
}
if(Type[0].equals("B"))
{
result.addValue(""+totalB);
}
return;
}
Input to the UDF will be SOURCE and an constant with value "A" or "B";
Thus mapping will be like this
SOURCE--------\
sumTotal--------------TARGETA
Constant("A")--/
SOURCE--------\
sumTotal--------------TARGETB
Constant("B")--/
Hope this resolves the problem.
Regards
Anupam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Anupam,
thank u for the response.
sorry for late response
the following error occurs when i test in IR
Source text of object Message Mapping: MM_Bank | http://filetofile has syntax errors: Source text of object Message Mapping: MM_Bank | http://filetofile has syntax errors: Source code has syntax error: D:\usr\sap\P71\DVEBMGS88\j2ee\cluster\server0\.\temp\classpath_resolver\Map1f288990d3c311e2886c00195b6bb510\source\com\sap\xi\tf\_MM_Bank_.java:266: cannot find symbol symbol : variable Type location: class com.sap.xi.tf._MM_Bank_ if(Type[0].equals("D")) ^ D:\usr\sap\P71\DVEBMGS88\j2ee\cluster\server0\.\temp\classpath_resolver\Map1f288990d3c311e2886c00195b6bb510\source\com\sap\xi\tf\_MM_Bank_.java:270: cannot find symbol symbol : variable Type location: class com.sap.xi.tf._MM_Bank_ if(Type[0].equals("C")) ^ Note: D:\usr\sap\P71\DVEBMGS88\j2ee\cluster\server0\.\temp\classpath_resolver\Map1f288990d3c311e2886c00195b6bb510\source\com\sap\xi\tf\_MM_Bank_.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: D:\usr\sap\P71\DVEBMGS88\j2ee\cluster\server0\.\temp\classpath_resolver\Map1f288990d3c311e2886c00195b6bb510\source\com\sap\xi\tf\_MM_Bank_.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 2 errors |
Also in your code i can see STRING TYPE[],but when i created its showing STRING [] TYPE.
please suggest me where i am doing mistake
Hi Raj,
I assume in your requeriments that the string length to the F is constant and the number to comma with variable length.
You can do this mapping:
You need to specify a dynamic substring easily with this UDF:
public String dynamicSubstring(String stringToSub, int begin, int end, Container container) throws StreamTransformationException{
return stringToSub.substring(begin,end);
}
With targetfiedb you copy this schema and you change only the const A by B.
With your example i get:
Regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You don't necessarily need a UDF, standard mapping functions should be sufficient.
Text functions
- substring
- equalsS (compare to Constant 'A' or 'B')
Statistic functions
- sum
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
The position of A and B in source value (currently i can see it as 15) is fixed or it can vary??
Thanks
Amit Srivastava
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
95 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.