cancel
Showing results for 
Search instead for 
Did you mean: 

only map certain amount of elements

peter_wallner2
Active Contributor
0 Kudos

Hello experts,

In my source structure I have 38 elements (number can vary) to map.

But I only want to map the first 15 elements.

In another step I want to map the next 15, so 16-30.

And in another step I want to map the rest, so element 31-38.

I somehow need a function I think that I can tell to take 1-15 and in the next mapping step I tell it to take 16-30 and at last 31-38.

Can I achieve that with graphical mapping? Does anyone have an idea?

Thank you,

Peter

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Peter,

Its possible when in the target side there is no mandataory (occurance is 1..1 or 1..unbounb) fields are exists or no mandatory segments exists.

You can do this also, you can duplicate the target structure 2 times (total 3 structures) then first time you can map the first 15 fields and second time you can map next 15 and so on. But this is the single mapping.

Regards

Ramesh

peter_wallner2
Active Contributor
0 Kudos

Hello Ramesh,

Thank you - this is helpful to me!

I know how to make 3 target structures but how do I split my source up into 3 parts? My source counts 38 elements and I need to split it up somehow.

How can I do this?

Thank you again!

Peter

Former Member
0 Kudos

Hi Peter,

do you need the result in different files?

Regards

Ivan

peter_wallner2
Active Contributor
0 Kudos

Hello Ivan,

No, it has to be in one file.

I will try a UDF now that counts my input elements (38) and then only returns number 1-15.

And then another UDF that returns 16-30 and so on.

I have never written a UDF alone but I will try.

Best regards,

Peter

Former Member
0 Kudos

In that case, You need to build a UDF to make the split.



public void printRange(String[]list, int start, int end, ResultList result, Container container){
if(list.length < end){
end = list.length;
}
if(list.length - 1 < start){
start = list.length -1 ;
}
for(int  i = start ; i < end ; i++){
  result.addValue(list<i>);
}

}


peter_wallner2
Active Contributor
0 Kudos

Thank you Ivan,

One question though: I am using XI 3.0.

When creating a UDF I can somehow only work with String and Result - I can not put "int" into the UDF. Is there a trick to do that??

Thank you again,

Peter

Former Member
0 Kudos

Sorry,

I forgot it,

Try with this,


public void printRange(String[]list, String starts, String ends, ResultList result, Container container){
int start = Integer.parseInt(starts);
int end= Integer.parseInt(ends);
if(list.length < end){
end = list.length;
}
if(list.length - 1 < start){
start = list.length -1 ;
}
for(int  i = start ; i < end ; i++){
  result.addValue(list<i>);
}
 
}

Regards

Ivan

Former Member
0 Kudos

Hi Peter,

No need to divide/split the source message, three times [ you are doing the mapping 3 times] (in the mapping) you can use the same sender structure, but every time in the mapping you can map what ever fields are required. the remaining fields you can leave.

In the java UDF, by default every thing treated as a String, so if you want to use int or float .. then we have to do the conversion.

int i= Integer.parseInt(input_data);

Regards

Ramesh

peter_wallner2
Active Contributor
0 Kudos

Hello Ivan,

Thanks again!

Somehow I can only create the following method head


public void printRange(String[] list,String[] starts,String[] ends,ResultList result,Container container){..}

And then I tried to convert "starts" and "ends" to "int":


int = Integer.parseInt(starts[]);
int = Integer.parseInt(ends[]);

but I get the following errors (the same for starts as well):


not a statement
int = Integer.parseInt(starts[]); 
^
 ';' expected
int = Integer.parseInt(starts[]);
^

Could you help me again, I don't know what could be wrong here!

Thank you!

Peter

Former Member
0 Kudos

Hi,

You need to assign a name to the variables and also indicate we want to take the first element of the array.


int start= Integer.parseInt(starts[0]);
int end= Integer.parseInt(ends[0]);

Regards

Ivan

peter_wallner2
Active Contributor
0 Kudos

Hi Ivan,

thank you again. I actually had assigned a name but forgot the 0 in the brackets [0].

I will have to play around for a little while now and get back to you when I am done. Thank you again!

Best regards,

Peter

peter_wallner2
Active Contributor
0 Kudos

Thank you Ivan, it works perfectly!

Best regards,

Peter

peter_wallner2
Active Contributor
0 Kudos

Hello Ramesh,

Thank you for your answer as well. I do have the same sender structure.

But I also need the target structure numerous times because the target structure is limited to 15 nodes.

If my source occurs more than 15 times I need the target more than once!

Thank you and best regards,

Peter

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

I do not understand What You need exactly. However You can explore multimapping option to generate more than one output file, another option is splitter your message using some module in the channel, finally You can use BPM functionality.

Regards

Ivan