cancel
Showing results for 
Search instead for 
Did you mean: 

Test if segment exist in XML IDOC source structure

laurent_touillaud
Contributor
0 Kudos

Hi,

I have a one to one mapping of IDOC ORDERS.

I need to test if the segment E1EDPT1 never exists in the xml instance.

If it does not i want to create it.

The problem is it takes context of the superiour node.

I don't want to add it if it exists in another context.

Example where it must not add the segments :

E1EDP01 (item1)

-E1EDPT1

--E1EDPT2

E1EDP01 (item2)

(segments does not exist)

E1EDP01 (item3)

-E1EDPT1

--E1EDPT2

Example where it must add the segments :

E1EDP01 (item1)

(segments does not exist)

E1EDP01 (item2)

(segments does not exist)

E1EDP01 (item3)

(segments does not exist)

I tried with MapWithDefault which is good for the second case but not the first as it adds the segments if it can't find the segments in node E1EDP01.

Thanks,

Laurent.

Accepted Solutions (0)

Answers (3)

Answers (3)

stefan_grube
Active Contributor
0 Kudos

When I understand right, you want to add all E1EDPT1, if none exists, but leave the queue as is, if any exists.

I think, you should do this with a UDF.

Regards

Stefan

laurent_touillaud
Contributor
0 Kudos

Hi Stefan,

yes that's what i mean!

Do you have some hints on how to create this UDF?

Best regards,

Laurent.

stefan_grube
Active Contributor
0 Kudos

Check this:

	public static void addValuesToContexts(String[] a, ResultList result,	Container container) {

		boolean found = false;

		for (int k = 0; k < a.length; k++)
			if (!a[k].equals(ResultList.CC))
				found = true;

		if (found) {
			for (int k = 0; k < a.length; k++)
				result.addValue(a[k]);
		} else {
			for (int k = 0; k < a.length; k++) {
				result.addValue("");
				result.addContextChange();
			}
			result.addValue("");
		}
	}

laurent_touillaud
Contributor
0 Kudos

Hi Stefan,

Thanks for your help.

I will try this and get back to you.

Regards,

Laurent.

Former Member
0 Kudos

Laurent,

He means if>sourcesegment>exists-->then (do your logic) else (logic).

Or

if>sourcesegment>exists-->createif.

All depends upon your logic also.

Regards,

---Satish

stefan_grube
Active Contributor
0 Kudos

You can use: exists - createif.

Then a "suppress" is added and keeps the contexts in order.

Regards

Stefan

laurent_touillaud
Contributor
0 Kudos

Hi Stefan,

You mean (exists - not - createif)?

I tried this but you have to add an (if else) function if the segment exists in the source otherwise it is not mapped. And this way it doesn't work in contexts neither.

My mapping looked like this :

E1EDPT2 - exists - not - <- IF

constant. (creates the segment) <- THEN

E1EDPT2 <- ELSE

This doesn't work as it checks in the same context.

I want to check in the whole xml structure, so i tried to change the context but this was not resolving my problem.

But maybe you meant something else?

Regards,

Laurent

former_member192892
Active Contributor
0 Kudos

Hi laurent,

I think the mapping you used, should occur for E1EDPT1 and not for E1EDPT2..

You should map E1EDPT2 one to one...

Can you pls try this??

laurent_touillaud
Contributor
0 Kudos

Hi Varun,

I tested this but if source doesn't have neither E1EDPT1 and E1EDPT2

the E1EDPT2 is not created as it's one to one mapping.

When i test it on example with segments E1EDPT1 and E1EDPT2 in source structure the contexts are not good. The empty text is put in the last item.

...

Regards,

Laurent.