cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping - Please Help

Former Member
0 Kudos

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!!!

Accepted Solutions (0)

Answers (9)

Answers (9)

Former Member
0 Kudos

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....

Former Member
0 Kudos

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

Former Member
0 Kudos

we are on SP12

Former Member
0 Kudos

"for" does not show up in blue on my code.... is there a reason for this?

Former Member
0 Kudos

Hi,

Tell your SP level?

Even if your "for" is not blue that should not be a problem.

Regards,

P.Venkat

Former Member
0 Kudos

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?

Former Member
0 Kudos

Hi,

Try the code in my previous post

and change the line as...

for(int j=0; j *** Less than symbol ***uniqID.length; j++){

Regards,

Uma

Message was edited by:

Uma Maheswari Soundara Pandian

Former Member
0 Kudos

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&lt;ID.length; k++){
     for(int j=0; j&lt;ID.length; j++){
        String temp = ID[k];
        ID[k] = ID[j];
        ID[j] = temp;
      }
}


I think this should work properly

Regards,

P.Venkat

Former Member
0 Kudos

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?

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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?

Former Member
0 Kudos

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

Former Member
0 Kudos

I do not see the sort function under node functions? Could you please confirm this is where it is located

Former Member
0 Kudos

Hi,

Sort function is under Node functions only. You need to traverse the functons right using arrow buttons provided to find the sort function. Or else use All functions and in that select node functions on left, u will see sort in the right side. add that.

Regards,

P.Venkat

Former Member
0 Kudos

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