cancel
Showing results for 
Search instead for 
Did you mean: 

Help on Concatenate ...

former_member181967
Participant
0 Kudos

Hi,

I have to face a concatenation between 2 fiels that occurs multiple times to only one string.

This functionality is used to insert values in an DB using JDBC and my structure contains others fields that are working properly but in this case only the first occurrence of those 2 fiels is inserted in DB.

Can anyone provide me some help ?!?!?

Thanks in advance.

JMMatos

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi JMMatos,

I guess, without seeing the Source and target structure, its difficult to solve your problem. Could you answer the below quesions, so that I can try:

i. The two fields that you are trying to concatenate - Are they within the same node?

ii. Did you try using the Test Tool of Map - Does the testing result in a correct Target Message?

Rgds

RC

former_member181967
Participant
0 Kudos

Hi RC,

Thanks for your time ... about your questions ...

i. the two fields belongs to the same node

--> Atributos 1..unbounded

--> Codigo 1..1

--> Valor 1..1

my target structure is

--> string_atr 0..1

and it must only happens one time ...

ii. in the Test Tool it really doesn't work ... only the first occurrence of my source (Codigo+Valor) is mapped ...

Do you have any suggestion ???

Thanks again...

JMMatos

Former Member
0 Kudos

Hi Jose,

Your target structure is showing 0...1. So the max reocrd is one. If you want to have multiple records make it 0...unbounded

Regards

Vijaya

Former Member
0 Kudos

Hi JMMatos,

Did Vijaya Kumari's response help you?

Else send the Exports of Source and Target structures.

Rgds

RC

former_member181967
Participant
0 Kudos

Hi Vijaya,

Sorry for delay of my response but I've been abroad ...

I understand what u mean but my target structure must only appear one time containing all the sets of my source structure.

The set (Codigo + Valor) should be repetead as many times it appears in the String field of my target structure separated by ;, like this:

Codigo;ValorCodigo;Valor ... Codigo;Valor

Thus this mean anything to u ??? thanks

JMMatos

Former Member
0 Kudos

Hi Jose,

If you have to map multiple occurences of your source structure element to a single element of the target structure, you need to write a User Defined function.

May be the following code sample would help you,

import com.sap.aii.mapping.api.*;

//Write your code here

StringBuffer message = new StringBuffer();

for(int i=0;i<a.length;i++)

{

if (!(a<i>.equalsIgnoreCase(ResultList.CC)))

{

message.append(a<i> + " ");

}

}

result.addValue(message.toString());

Regards,

Padmaja

PS: Pls reward points if you found my response useful.

Former Member
0 Kudos

Hey,

jus now tried ur scenario,it works fine

u need to write a user defined function.

first u concatenate Codigo and Valor,then in the resulting output do remove context,

so codigo--

valor -- concatenate---->removecontext

then use a user defined function with 2 inputs one as Atributos(the parent node) and the other as the output coming from removecontext,these two inputs will be defined as a and b in the user defined function respectively.

So for all the occurance of parent node,the values of codig and valor will be concatenated and sent to the string using this UDF

<b>

In the user defined function write the following code

<b>int i=0;

String s="";

for(i=1;i<a.length;i++)

{

s=s+(b[i-1] ";" b<i>);

}

result.addValue(s</b>);</b>

and from the userdefined function map the output to the target structure node String

just try.i tried it worked fine.

cheers

jithesh

Message was edited by: jithesh balakrishnan

former_member181967
Participant
0 Kudos

Hi Padmaja,

Could u help defining the Arguments to my UDF??? It seems to me that i should use the main node Atributos as input which corresponds to var a in your code ... it is right ?!?!? and in tems of Cache what should i choose ??

Regards,

JMMatos

former_member181967
Participant
0 Kudos

Hi Jithesh,

Defining my UDF as you kindly indicated i get three errors in result test:

1)cannot resolve symbol symbol : variable length location: class java.lang.String for(i=1;i<a.length;i++)

2)array required, but java.lang.String found s=s+(b[i-1] ";" b);

3)cannot resolve symbol symbol : variable result location: class com.sap.xi.tf._MM_Servicos_Cria_Produto_BDC_ result.addValue(s);

Can u help me???

Regards,

JMMatos

Former Member
0 Kudos

Hi Jose

you should map like this

Codigo>your user defined function->your target node

Atributos is the parent node whose occurence is unbounded..

the cache type you should use is "Queue"

Hope this helps

Best Regards,

Padmaja

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi ,

In the following code when I executed its giving the below error

Code:

//Write your code here

StringBuffer message = new StringBuffer();

for(int i=0;i<a.length;i++)

{

if (!(a.equalsIgnoreCase(ResultList.CC)))

{

message.append(a + " ");

}

}

result.addValue(message.toString());

Error:

cannot resolve symbol symbol : method equalsIgnoreCase (java.lang.String) location: class java.lang.String[] if (!(a.equalsIgnoreCase(ResultList.CC)))

My Scenario is similar to this one where I

RootNode 0..unbounded

ChildNode 0..1

This root node will be repeated mutiple times and on the target I have to map to field for all the occurences of childNode into one element.

Thanks in advance...

Former Member
0 Kudos

Hi,

Make sure that the target field occurance is 0 to unbounded or 1 to unbounded.

We would be able to help you better if you could provide the source and target structures here.

Regards,

Smitha.