cancel
Showing results for 
Search instead for 
Did you mean: 

Combining occurences of different segments at same level

Former Member
0 Kudos

Hi All,

I have two different segments(VOL1 & VOL2) at same level on source side.

Say first segment repeats two times and second segment repeat three times.

I need to produce a single queue having combined occurences of these two segments which has five occurences in a single queue.

Please provide inputs how to achieve this.

Thanks,

Marz

Accepted Solutions (1)

Accepted Solutions (1)

markangelo_dihiansan
Active Contributor
0 Kudos

Hi,

This is not possible without using UDF. What you can do is to use a mapping like this:

All UDF's must be of Context type, the simplified version would be:

VOL1 --> removeContext --> UDF1 --> concat: / --> UDF2 --> Target

VOL2 --> removeContext --> UDF1 -


> /

UDF1 is a UDF that concats all values of VOL1 or VOL2, while UDF2 is a UDF that splits the combined values of VOL1 and VOL2 that has undergone the transformation

For UDF1, you can use this code: input argument is a

StringBuffer e = new StringBuffer();

String b = null;

for (int i=0;i<a.length;i+){e = e.append("/"a<i>);}

b = e.toString();

b = b.substring(1,b.length());

result.addValue(b);

For UDF2, you can use this code: input argument is input

String b[] = input[0].split("/");

for (int a=0;a<b.length;a++){result.addValue(b[a]);}

Hope this helps,

Former Member
0 Kudos

Thanks Mark. solved the problem.

Thanks,

Marz

Former Member
0 Kudos

Hi Mark,

Please remove a little doubt with a UDF here

I need to check if value returned after concatenation contains only ('/////')

I need to use

String b[] = input[0].split(""); in second UDF

else

I need to use String b[] = input[0].split("/"); in second UDF

Could you please help with this? Is there any standard function which can check all values within a field for (/) ?

Thanks,

Marz

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Marz,

I'll get back to you on this.

Regards

Edited by: Mark Dihiansan on Feb 26, 2009 4:25 PM

Former Member
0 Kudos

Mark,

Say first segment repeat 2 times & 2nd segment repeat 3 times,then concatenation after above written 1st UDF will give value as [/////].

But if first segment repeat 2 times & 2nd segment repeat 3 times, and fields of these segments will be having some values, if I apply same UDF to fields instead of segments level, then concatenation after above written 1st UDF will give value as [/abc/abc/abc/abc/abc].

Now I need to ensure that, when I recieve value in format [/////], I should split it on basis of String b[] = input[0].split("") i.e blank space as seperator.

But if I recieve value in format [/abc/abc/abc/abc/abc], i should split it on basis of String b[] = input[0].split("/") i.e '/" as seperator.

Hope I am able to put it clear.

Thanks,

Marz

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Marz,

Just edit the code for UDF1 to this:

StringBuffer e = new StringBuffer();

String b = null;

for (int i=0;i<a.length;i+){e = e.append("/"a<i> + " ");}

b = e.toString();

b = b.substring(1,b.length());

result.addValue(b);

This should be able to handle the blank inputs. Basically, I just added a space so that should the inputs be blank, it will still have a value.

Hope this helps,

Regards,

Former Member
0 Kudos

Thanks Mark,solved the problem.

Regards,

Marz

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi,

Please do the following mapping

Vol1 -- copyValue[0]- Target

Vol1 -- copyValue[1]- Target

Vol2 -- copyValue[0]- Target

Vol2 -- copyValue[1]- Target

Vol2-- copyValue[2]- Target

Provided the Taget has to be duplicated 5 times.

Thanks,

Kiran

Edited by: Kiran on Feb 23, 2009 9:28 AM

Former Member
0 Kudos

If you really want to make sure that the target message contains the combined data from VOL1 and VOL2.

I would suggest to "duplicate subtree" in the Graphical mapper.

Vol_1 --> Target_1

Vol_1 --> Target_1

Vol_1 --> Target_1

Duplicate subtree (Target_1)

Vol_2 --> Target_1

Vol_2 --> Target_1

See SAP Help

http://help.sap.com/saphelp_nw04/helpdata/en/e8/a27440a3f0711de10000000a1550b0/frameset.htm

GReets

Former Member
0 Kudos

Marz,

CAn you please provide some example data.

The problem is not quite clear to me.

Greets

Former Member
0 Kudos

HI,

Check if there is any common field btw the two segments VOL1 and VOL2.

If yes, set its context to the header(which contains VOL1 and VOL2 segments).

sourcefield(with header context) -> count-> Target.. gives the number of occurrances of both the segments.

or,

sourcefield(default context) -> remove contexts->... gives all the occurances of the field in both the segments on a single queue.

Just try whether, the above suits your requirement.

Regards,

Swetha.

Former Member
0 Kudos

Thanks Rajeev/Swetha for inputs,

But this willn't work as it will give right output only when a single same segment repeat multiple times.

But for my case, there are two different segments, but both of which are at same level just under Message type name(means default and only context will be message type name).

For my structure, at top level ,I have a message type name under which i have two different segments (Balance Records) and (Total Records) both at same level. Both of these segments can repeat multiple times.

Now I need to count combine occurences of both of these differernt segments at runtime and produce a target segment corresonding to combined occurences of these two.

Please provide help for achieveing this.

Thanks,

Marz

Former Member
0 Kudos

Marz,

If I understand your requirement correctly, you should use the 'duplicate subtree' option on the target segment (right-click the segment in the target message structure, select 'duplicate subtree'). You then use the first occurrence of the segment to map values from VOL1, and the second to map values from VOL2:

[VOL1] ------ [TARGETSEGMENT]
[VOL2] ------ [TARGETSEGMENT]

Kind regards,

Koen

Former Member
0 Kudos

Hi,

take any field of VOL1 segment and set its context to the Header node under which VOL1 and VOL2 are present..........then using exists and creatIf function, you can generate your target node.

Regards,

Rajeev Gupta