on 06-11-2009 6:26 PM
Experts;
below is code: i want to return back array;
it doesnt throw any error but it gives output as [Ljava.lang.String;@4a4cd40b..
public void collectSICCODE(String[] cod, ResultList result, Container container) throws StreamTransformationException{
String[] myArray = new String[cod.length];
for( int i=0; i<cod.length; i++)
{
myArray<i> = cod<i>; // assign the value to index i, replace ""+i with your value.
}
result.addValue(myArray);
}
You have to add value after value to the resultset & not an arraylist.
As you can see from result.AddValue i/p param is String & not an array.
http://help.sap.com/saphelp_nw04/helpdata/en/b1/83a09f668320419dbe00a741e0fe6a/content.htm
Move result.AddValue() into the loop & provide the value.
-SM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try the below UDF and see if it works
public void collectSICCODE(String[] cod, ResultList result, Container container) throws StreamTransformationException{
String myArray ;
for( int i=0; i<cod.length; i++)
{
myArray = myArray + cod<i>; // assign the value to index i, replace ""+i with your value.
}
result.addValue(myArray);
}
Thanks
Aamir
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Aamir,
it throws me error
at +
myArray = myArray + cod<i>;
Function collectSICCODE, Line 10:
incompatible types found : java.lang.String required: java.lang.String[] myArray = myArray + cod<i>; // assign the value to index i, replace ""+i with your value. ^ Note: /usr/sap/XID/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map4588815056ca11debc3200212814d176/source/com/sap/xi/tf/_CreateCustomerMaster_to_CreateCustomerMaster_.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. 1 error
could you please replace
>>String myArray ;
with
>>String myArray = " ";
Since its an attribute,you will be able to assign only one value to it,so you need to concatenate all values of the sender node and then pass it on to the receiver side.
The UDF given by Amit looks good to me as well.
Thanks
Aamir
there was some syntax error.. that got resolved..
the solution you provided is also provided by Amit, also i have tried that before..
but here it is returning one string as result, it is not an array right?
how do i assisgn this to an array? the whole result is going to be first one value of an array..
Please try the following code
public void collectSICCODE(String[] cod, ResultList result, Container container) throws StreamTransformationException{
String[] myArray = new String[cod.length];
for( int i=0; i<cod.length; i++)
{
myArray<i> = cod<i>; // assign the value to index i, replace ""+i with your value.
result.addValue(myArray<i>);
}
}
You can not return an array from a UDF.UDF's only returns output in the form of a string(single value or whole queue).
Thanks
Aamir
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
>>if UDF return single values
It does not returns only single value
It return String values.this can be a single value or it can be multiple values( kind of like an array)
the statement result.addValue in the UDF will create a String array like structure which will keep on appending values to itself after every iteration.once the end of UDF is reached,the variable "result" will contain a list of all the values,you can simply map the output of UDF to the node of receiver side which is expecting arrayType value.
Thanks
Aamir
While sending Webservice request it dosen't carry info whether the data is string or float or int or arraylist... These types are used only during programming & defining the structure. (I don't think you can define an arraylist as your element type.)
So you should really not worry about arraylist. Add the values in UDF to resultlist & test your map. Check in the test tab if the output XML is as per what you wanted....
-SM
Hi,
The code looks correct. It should populate the array with all the values. It looks like in input string array (cod) has only one value and so one value is getting pouplated in result. Just for debugging purpose, can you try the code given below and see what is the value you can see in ResultList
public void collectSICCODE(String[] cod, ResultList result, Container container) throws StreamTransformationException{
String[] myArray = new String[cod.length];
for( int i=0; i<cod.length; i++)
{
myArray<i> = cod<i>; // assign the value to index i, replace ""+i with your value.
}
result.addValue(""+cod.length);
}
Amit
>>solid circle with down point arrow on circle
This is an attribute,not a node element.
Please look at the below link and see if you are mapping it to an attribute or an actual node
http://help.sap.com/saphelp_nw04s/helpdata/en/8a/7bc84841f14b47aa769c9219452229/frameset.htm
Thanks
Aamir
strange! can you try the code given below and tell me the output. I just want to narrow down the issue.
public void collectSICCODE(String[] cod, ResultList result, Container container) throws StreamTransformationException{
String[] myArray = new String[cod.length];
String tempStr ="";
for( int i=0; i<cod.length; i++)
{
tempStr = tempStr + cod<i>+ ",";
}
result.addValue(tempStr);
}
aha,that's the issue
you can not have multiple occurrences of an attribute within the same data element.
Attributes are either optional or Required,but they cant occur multiple times within the same payload.
One thing you can do is concatenate all values from the UDF and send then send them to the receiver system.but you can't send them separately as long as its defined as an attribute.
Thanks
Aamir
Aamir,
sorry for the confusion
Source
- customers - occurence 1..1 (node)
- SIC_Codes - occurence 0..unbounded (node)
- Customers_SIC_code - occurence 0..1 (string)
to get
target
- customers - occurence 1 (node)
- SIC_Codes - occurence 1 (node)
- p2:arrayType - is an attribute
i want all Customers_SIC_code to be sent as an array in p2:arrayType that is why the occurence of the SIC_Codes is 1 at the target and unbounded at the source..
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
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.