cancel
Showing results for 
Search instead for 
Did you mean: 

Context Handling problem

0 Kudos

Hi all,

I have a problem with a context handling requirement. I think UDF is needed in this case but I don't know where to start. Please see below for the scenario:

I have an input structure like this:

segment1

field1

segment2

field2

segment3

field3

node2

field2

node3

field3

node3

field3

the fields will corelate the segment and the node. so for this structure, segment2 and node2 are corelated. Actually, node2 is under segment2.

here's my desired output to make things clearer:

segment1

field1

segment2

field2

node2

field2

segment3

field3

node3

field3

node3

field3

field1 sample value. ex. 0000000001

all field2 have the same value. Value from both segment2 and node2 of field2 is the same. ex. 0000000002

all field3 have the same value. Value from both segment3 and the 2 node3s of field3 is the same. ex. 0000000003

In my current mapping, I'm getting this erroneous output:

segment1

field1

node2

field2

segment2

field2

node3

field3

segment3

field3

node3

field3

The nodes are not in their correct segments. node2 is one level higher because there was no node1.

Occurrence of segments are 1..unbounded. nodes are 0..unbounded.

Thanks all.

Regards,

SAPenthusiast

Accepted Solutions (1)

Accepted Solutions (1)

markangelo_dihiansan
Active Contributor
0 Kudos

Hello,

The nodes are not in their correct segments. node2 is one level higher because there was no node1.

You can use mapWithDefault for your requirement e.g


Source -> mapWithDefault: -> Target

e.g suppressed, 1 , 1 output in target will be , 1, 1

So whenever Source field is not existing, it will be created by using mapWithDefault (value depends on what you set it), hence the context structure count will be corrected.

Hope this helps,

Mark

0 Kudos

I'm afraid that's incorrect Mark. Mapwithdefault will not work since there are no suppressed segments. XI does not know that there's a missing node1 in segment1..

markangelo_dihiansan
Active Contributor
0 Kudos

Hello,

Can we ask for an actual sample input/output XML so that we'll be able to help you more?

Regards,

Mark

0 Kudos

Okay, this is a much simpler explanation:

Input1 will be compared to the values of Input2 to check if their values are equal. Example:

Input1

111

111

222

333

333

Input2

222

222

333

Current output

false

false

false

false

true

desired output is

false

false

true

true

true

because the input2 should look like this (no 111):

suppress

suppress

222

222

333

markangelo_dihiansan
Active Contributor
0 Kudos

Hello,

You need to use UDF for this:

UDF type is Context

Arguments:

input1

input2


HashMap map = new HashMap();

for(int a=0;a<input2.length;a++){
	if(!map.containsKey(input2[a])){
		map.put(input2[a],"");
	}
}

for(int a=0;a<input1.length;a++){
	if(map.containsKey(input1[a])){
		result.addValue("true");
	}
	else{
		result.addValue("false");
	}
}

mapping is something like this:


input1 -> removeContext -> UDF -> target
input2 -> removeContext -> /

Hope this helps,

Mark

Answers (0)