on 04-25-2012 8:21 PM
Hi ,
I tried to use Concatenate function in graphical mapping but does not seem to work. How to Concatenate 5 different fields to on target field?
Do I need to write a UDF?
eg, Val1
Val2
Val3
Val4
Val5
Concatenate above 5 fields to one target field String without delimiter ?
Please advice.
Thanks,
Teresa
Hi Teresa,
I've edited this answers because only works if the values comes from the same source field, the same tag repeated several times.
If you want to follow the Grzegorz Glowacki option and using an UDF, you could improve the concatenate function to use it for n strings and put the function in a function library for future mappings.
You could put like category type all values on context or all values on queue, it depens how the values come to the UDF, and later:
imports java.lang.*;
public void nConcatenate(String input[], ResultList result, container Container){
String stringConcatenated = "";
for (i = 0; i < input.length; i++){
stringConcatenated += input[i];
}
result.addValue(stringConcatenated);
}
Finally you have an UDF that you could use to concatenate five or the number or n strings that come in the input queue
Regards.
Message was edited by: Iñaki Vila
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Teresa,
I believe this is because of the UDF: it concatenates all the values from one queue, and not five different fields (five different queues). For your requirement, use something more like Former Membermentioned. Still, if the queues of the input fields are not similar (in terms of contexts), the UDF might produce unexpected results.
Hope this helps,
Greg
Hi,
I never faced prob with concat like gicing supress value, the simple solution to debug your issue is use mapwithdefualt(blank) and use standard function concatc and check the result.
As other expecrts suggested using UDF for this requirement is good idea but debbuging is little bit risky.
Regards,
Raj
This is not hard requirement. You can pretty much handle through standard function or UDF. If you don't want UDF, go as Raja pointed out. I have shown above code if you are getting blank values in the runtime. Use any of the above solutions. If you get repeated values in the queue, then you might have to pass five string list for each parameter. If you have issues, provide your mapping requirements here.
Hi Baskar,
Requirement is between mapping a CRM idoc and PORDCH03 idoc. I need to concatenate the following fields from CRM idoc which belong to different segments.
Where should the target segment E1BPMEPOTEXT be mapped as each of the source fields come from different segments ? Should I change the Context of the source fields to the Main segment in the source like IDOC ?
Thanks,
Teresa
If I understood correctly, Looks like you need to concat different idoc field segments to the target field.
Is that so? You don' t have values coming from multiple context of the same field in the source queue.
Just use the above UDF. Use execution type single values and select parameters five as var1, var2...var5. Java Type as String for all of them. use the above UDF and see the result.
input five fields map to udf and udf to target field.
Hi Baskar,
I saved and activated as you mentioned. I still do not see the inputs when i define the category as single values.
Also I am getting following error during activation.
Function ConcateString, Line 17: cannot find symbol symbol : variable result location: class com.sap.xi.tf._MES_MAP_CRM_EXT result.addValue(sBuf.toString()); ^ Note: /usr/sap/DX7/DVEBMGS00/j2ee/cluster/server2/./temp/classpath_resolver/Mapa4f36d2f8fcd11e1bbc1000000794138/source/com/sap/xi/tf/_MES_MAP_CRM_EXT_SPM2Paragon_TO_PORDCH03_.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. 1 error
Hi Baskar... Apprecaite your help. I activated it succesfully. Now i have these 5 fields from different segments in Source CRM idoc when I use the UDF I cannot input any of these . When I double click on UDF i see 5 variable var1 , var2 , var3. How do I map the source fields to these?
Thanks again.
Thanks Baskar. One more issue How to deal with Contexts ? I see the fields in the source segment have different contexts. I think this is causing the UDF to not work properly. Do i need to change the contexts of the source ? The UDF works perfectly fine when I tried with Constants.
Please advice.
Hi Teresa,
If you need to simply adjust the context changes between different queues, maybe you could make use of the formatByExample function? But bear that in mind that working with contexts actually depends strictly on your functional requirement.
Hope this helps,
Greg
The above UDF is not the right candidate for handling values in contexts. I already asked this question in the above replies. You might have to change the code to handle it in different way. But as Greg said its truly based on business requirement. I cannot fully guarantee that this will help your need.
IMO, efficient way of handling string array concat is through java generic. Unfortunately it is not so easy to handle using UDF rather I would prefer java mapping for this. You might want to try the below logic in UDF and see how that helps.
You need to individually concat five different segments value for each index and return the ouput as a single string array.
Change the execution type to All values of context
Set context for each element to parent node
Use 6 arguments in the method as below
Sample code
Note: Below I default the size of the output array length using the first string array list length. What will happen if the first string array list has some empty values. In that case length might be lesser compared to other string arrays length.
Hi Baskar,
I am getting the following error below. Is th UDF i have typed correct?
Function Concatarr, Line 2: arrOutput is already defined in Concatarr(java.lang.String[],java.lang.String[],java.lang.String[],java.lang.String[],java.lang.String[],java.lang.String[],java.lang.String[],com.sap.aii.mappingtool.tf7.rt.ResultList,com.sap.aii.mappingtool.tf7.rt.Container) String[] arrOutput = new String[arr1.length]; ^ Function Concatarr, Line 10: cannot find symbol symbol : variable result location: class com.sap.xi.tf._MES_MAP_CRM_EXT_PORDCH03_ result.addValue(arrOutput); ^ . Note: Recompile with -Xlint:deprecation for details. 2 errors
{ String[] arrOutput = new String[arr1.length];
for(int i = 0 ; i < arrOutput.length; i++)
{
arrOutput[i] = arr1[i] + arr2[i] + arr3[i] + arr4[i] + arr5[i] + arr6[i] + arr7[i];
}
result.addValue(arrOutput);
}
Thanks,
Teresa
That was sample code. When you create method with execution type as All values of context you get below method signatures with ResultList as parameter.
Here is below code.
public void concatStringArray(String[] arr1, String[] arr2, String[] arr3, String[] arr4 String[] arr5, ResultList result, Container container) throws StreamTransformationException{
String[] arrOutput = new String[arr1.length];
for(int i =0; i < arrOutput.length; i++){
arrOutput[i] = arr1[i] + arr2 [i] + arr3[i] + arr4[i] + arr5 [i];
}
result.addValue(arrOutput);
}
Hi Baskar,
I am getting an error is there another bracket that is needed.
Function Concat, Line 7: open bracket '{' missing for closed bracket '}': } ^
public void Concat(String[] arr1, String[] arr2, String[] arr3, String[] arr4, String[] arr5, String[] arr6, String[] arr7, ResultList arrOutput, Container container) throws StreamTransformationException{
String stringConcatenated = "";
for (i = 0; i < input.length; i++){
stringConcatenated += input[i];
}
result.addValue(stringConcatenated);
}
Thanks,
Teresa
use below code, I said
public void concatStringArray(String[] arr1, String[] arr2, String[] arr3, String[] arr4 String[] arr5, ResultList result, Container container) throws StreamTransformationException{
String[] arrOutput = new String[arr1.length];
for(int i =0; i < arrOutput.length; i++){
arrOutput[i] = arr1[i] + arr2 [i] + arr3[i] + arr4[i] + arr5 [i];
}
result.addValue(arrOutput);
}
I can post any attachments here in SDN. My file size is in form of JPEG or PNG and less than 1 MB. Is there any other file extension that is acceptable?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm not in favor of the concat funciton. I would go with UDF, much cleaner.
You will need 5 arguments
String concatValues;
concatValue = val1 + val2 + val3 + val4 + val5;
return concatValues'
something similar to above.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I would use the UDF and make it simpler.
create method using 5 arguments
StringBuffer sBuf = new StringBuffer();
sBuf = var1.length()>0? sBuf.append(var1): sBuf.append("");
sBuf = var2.length()>0? sBuf.append(var2): sBuf.append("");
sBuf = var3.length()>0? sBuf.append(var3): sBuf.append("");
sBuf = var4.length()>0? sBuf.append(var4): sBuf.append("");
sBuf = var5.length()>0? sBuf.append(var5): sBuf.append("");
result.addValue(sBuf.toString());
source five fields --> UDF --> target field
Modified code to handle if the value comes empty.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Baskar,
I am getting the following error below for your UDF.
Thanks,
Teresa
cannot find symbol symbol : method length() location: class java.lang.String[] sBuf = var1.length()>0? sBuf.append(var1): sBuf.append(""); ^ Function ConcatStr, Line 5: cannot find symbol symbol : method length() location: class java.lang.String[] sBuf = var2.length()>0? sBuf.append(var2): sBuf.append(""); ^ Function ConcatStr, Line 7: cannot find symbol symbol : method length() location: class java.lang.String[] sBuf = var3.length()>0? sBuf.append(var3): sBuf.append(""); ^ Function ConcatStr, Line 9: cannot find symbol symbol : method length() location: class java.lang.String[] sBuf = var4.length()>0? sBuf.append(var4): sBuf.append(""); ^ Function ConcatStr, Line 11: cannot find symbol symbol : method length() location: class java.lang.String[] sBuf = var5.length()>0? sBuf.append(var5): sBuf.append("")
The UDF is coded for passing five string arguments not as string []. If you pass five string[] then the above code has to be modified. Again, we reference the length in the arrray it is just length not length().
Are you having repeated values in the Queue? If so the above logic would not work.
Hi Teresa,
Standard PI's concat function can only concatenate two arguments, but still you can use one concat by another to achieve the required result. Just map the result of the first concat as one of the parameters of the later concat, and so on. UDF can also be an alternative, if you want to keep the mapping more readable.
Hope this helps,
Greg
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Teresa,
I don't remember seeing a SUPPRESS as an output from concat function. As far as I remember, it takes the value from the previous context, if there is a value missing in the next one. So in each context, you will have as many outputs, as in the input parameter that has more values in that context.
Are you sure the SUPPRESS is not generated by another function, like createIf (before or after concat)? Could you please post a screenshot from Display Queue of the concat function?
Regards,
Greg
User | Count |
---|---|
81 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.