on 12-11-2006 8:42 AM
Hi Experts,
We would appreciate your help on one thing,
We are trying to do a mapping but I think we are going to need an advanced UDF for it and I don't know how to write one... so any of you Java Programmers out there I would much appreciate some code
Basically the structure is this (Bare in mind Recordset is the parent node to records and records is the parent node to ID)
Recordset
Records
ID
Recordset
Records
ID
Recordset
Records
ID
Recordset
Records
ID
Recordset
Records
ID
Recordset
Records
ID
Now what I want to do is map the first instance of the ID Field.
So basically I need to the function to go through all the context/occurences of ID and map only the ID's which occur first! and not to map the duplicate ID's.
So for example if my source was
Recordset
Records
ID - 1
Recordset
Records
ID - 2
Recordset
Records
ID - 3
Recordset
Records
ID - 2
Recordset
Records
ID - 4
Recordset
Records
ID - 1
Then my target should have the values
1
2
3
4
and the second instance of 1 and 2 would be ignored...
Could someone please give me some code that would do this in an advanced UDF
Urgent!!!
P Venkat even when I typr your new code I get
Source code has syntax error: /usr/sap/CXD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapcc74ed4088fd11dbca2b000d60de069c/source/com/sap/xi/tf/_MM_Source_Target_.java:29: cannot resolve symbol symbol : variable ID location: class com.sap.xi.tf._MM_Source_Target_ for (int k=0; k<ID.length; k+){ ^ /usr/sap/CXD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapcc74ed4088fd11dbca2b000d60de069c/source/com/sap/xi/tf/_MM_Source_Target_.java:30: cannot resolve symbol symbol : variable ID location: class com.sap.xi.tf._MM_Source_Target_ for (int j=0; j<ID.length; j+){ ^ /usr/sap/CXD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapcc74ed4088fd11dbca2b000d60de069c/source/com/sap/xi/tf/_MM_Source_Target_.java:31: cannot resolve symbol symbol : variable ID location: class com.sap.xi.tf._MM_Source_Target_ String temp = ID[k]; ^ /usr/sap/CXD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapcc74ed4088fd11dbca2b000d60de069c/source/com/sap/xi/tf/_MM_Source_Target_.java:32: cannot resolve symbol symbol : variable ID location: class com.sap.xi.tf._MM_Source_Target_ ID[k] = ID[j]; ^ /usr/sap/CXD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapcc74ed4088fd11dbca2b000d60de069c/source/com/sap/xi/tf/_MM_Source_Target_.java:32: cannot resolve symbol symbol : variable ID location: class com.sap.xi.tf._MM_Source_Target_ ID[k] = ID[j]; ^ /usr/sap/CXD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapcc74ed4088fd11dbca2b000d60de069c/source/com/sap/xi/tf/_MM_Source_Target_.java:33: cannot resolve symbol symbol : variable ID location: class com.sap.xi.tf._MM_Source_Target_ ID[j] = temp; ^ 6 errors
Any IDeas?
:-)... All I need now is to sort my values and I am away....
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
While creating the User defined function you will have a pop up window. In that there will be variables column. There will be an entry 'a' change that to ID.
And if in this line "for (int j=0; j><ID.length; j++){ "
it should be j *less than symbol* ID.length
hope it should work now.
Regards,
P.Venkat
we are on SP12
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
"for" does not show up in blue on my code.... is there a reason for this?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Guys I am still getting this sort of error for both codes.
Source code has syntax error: /usr/sap/CXD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map79f4eb5088f911db980f000d60de069c/source/com/sap/xi/tf/_MM_Source_Target_.java:30: illegal start of expression for (int j=0; j><ID.length; j++){ ^ 1 error
Are you saying I should not copy the code but type it in manually? Could you please confirm tht both codes work for you guys?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I dont know how the sort function is missing. May be some difference in SP level. Specify which SP level u r using.
Code to Sort is as follows:
Give input name as ID
for(int k=0; k<ID.length; k++){
for(int j=0; j<ID.length; j++){
String temp = ID[k];
ID[k] = ID[j];
ID[j] = temp;
}
}
I think this should work properly
Regards,
P.Venkat
Uma I get the following error
Source code has syntax error:
/usr/sap/CXD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map30f36a0088f711db8351000d60de069c/source/com/sap/xi/tf/_MM_Source_Target_.java:35: illegal start of expression
for(int j=0; j><uniqID.length; j++){
^
Also is this code to sort the values or to carry out the whole scenario?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Try this...
<b>This is to carry out whole scenario...
Source ID ---> UDF ---> Target ID</b>
//write your code here
String [] uniqID = new String[ID.length];
int found;
int k=0;
for(int ii=0; ii<ID.length; ii++){
found = 0;
for(int j=0; j<uniqID.length; j++){
if(ID[ii].equals(uniqID[j]))
found = 1;
}
if(found == 0){
result.addValue(ID[ii]);
uniqID[k]=ID[ii];
k++;
}
}
Some problem in copy-paste!
Regards,
Uma
Message was edited by:
Uma Maheswari Soundara Pandian
Hi,
Try this code in UDF. It worked for me.
Here ID is the input Argument in UDF and keep the cache level as Queue in UDF.
In mapping, right click on ID and change the contrext to Recordset.
//write your code here
String [] uniqID = new String[ID.length];
int found;
int k=0;
for(int i=0; i<ID.length; i++){
found = 0;
for(int j=0; j<uniqID.length; j++){
if(ID<i>.equals(uniqID[j]))
found = 1;
}
if(found == 0){
result.addValue(ID<i>);
uniqID[k]=ID<i>;
k++;
}
}
Regards,
Uma
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Venkat thank you for your response... Unfortunately this function does not seem to exist... However the split by Value works really well...
All I need now is to sort the values first then it will be the ideal answer...
Could you possibly give me some java code to sort the values?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I dont know how the sort function is missing. May be some difference in SP level. Specify which SP level u r using.
Code to Sort is as follows:
Give input name as ID
for(int k=0; k<ID.length; k++){
for(int j=0; j<ID.length; j++){
String temp = ID[k];
ID[k] = ID[j];
ID[j] = temp;
}
}
Regards,
P.Venkat
Message was edited by:
Venkataramanan Parameswaran
Message was edited by:
Venkataramanan Parameswaran
I do not see the sort function under node functions? Could you please confirm this is where it is located
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I think u can do this in Graphical mapping itself.
Try this Mapping:
ID (set context to top level) --- sort(Node functions) -- splitbyvalue(Properties: after a change in value) ---- collapseContexts -- outputNode
Regards,
P.Venkat
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
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.