cancel
Showing results for 
Search instead for 
Did you mean: 

How to avoid creating the target node if all the source fields are empty

former_member190543
Participant
0 Kudos

Hi guys,

Can you help me with a mapping issue please?

My scenario is SOAP to BAPI. When there are no values in some of the source nodes, BAPI is having empty row created (during debug) and returning BAPI error. It doesn't work whether I have the mapping or remove it altogether from the config. But when I have the mapping and remove unused target nodes mapping it is working and successful response is received.

Now my question is... how can we use graphical mapping to avoid creating the respective target node if none of the input values are present under a source node. If at least one source field is present under a node, it should only then create the respective target node. Of course I can use "Map if exist" for all source fields or "map if not empty" but I have many fields in some of the source nodes.

Any idea how to achieve this please? Preferably graphical, but any help with UDF is appreciated as well.

Thanks in advance.

Ramesh.

Accepted Solutions (0)

Answers (4)

Answers (4)

former_member190293
Active Contributor
0 Kudos

Hi Ramesh!

UDF:

Mapping:

Mapping result:

Regards, Evgeniy.

former_member190293
Active Contributor
0 Kudos

Optimized UDF code:

Regards, Evgeniy.

former_member190293
Active Contributor
0 Kudos

Hi Ramesh!

If you need to check node only for any subnode existance, you can try a kind of "tricky" way:

Use Text function "EqualsS" where the first argument is your node with option "Return as XML tree" and the second is constant representing value of empty node, for example "<MyNode/>" If values are equal - your node is empty.

I can't test it myself now but you can try.

Regards, Evgeniy.

anupam_ghosh2
Active Contributor
0 Kudos

Hi Evgeniy,

                  Can you please let us know where will you direct the output of the text function.

Secondly even if you are able to direct the output to entire xml of target, there is another issue.

How many node names you need to compare to with entire source XML. As per first post by Ramesh, there are lot many fields like this.

I do not mean to offend you in any way just curious to know.

Regards

Anupam

former_member190293
Active Contributor
0 Kudos

Hi, Anupam!

1. EqualsS returns true or false. You use CreateIf for target node creation when EqualsS returns false (node is not empty).

2. You don't need to check every subnode. When you use XML tree representation, it returns something like this: "<Node><subnode1>value</subnode1><subnode2>value</subnode2></Node>

Node without any subnodes looks like <Node/>.

We just compare actual node XML representation with the same node representation when it's empty. If the values are equal - node is empty.

It's just an idea which requires testing.

Regards, Evgeniy.

former_member190543
Participant
0 Kudos

Hi Evgeniy,

Thanks for elaborating on Anupam's question. That sounds like it can work.

Let me try that and get back to you.

Thanks,

Ramesh.

anupam_ghosh2
Active Contributor
0 Kudos

Hi Evgeniy,

               

         Thank you so much for your response.

Here are few points which I feel about this solution

1. Testing with EqualsS will always return false since comparison between xml tree and a single blank node will never match except for the case all sub nodes are empty and header node has formed.

2.  You are comparing the header node value of a segment if it is empty.

This case does not take care of individual fields withing the header node. So in case some field value comes as blank where as others are coming with a value then this match will not give you proper result. Somewhere you need to compare with individual field node names. Take this case

<Node><subnode1/><subnode2>value</subnode2><subnode3/></Node>

here you need to compare individually to remove empty nodes.

Regards

Anupam

former_member190293
Active Contributor
0 Kudos

Hi, Anupam!

Yes this doesn't work in case of empty values in subnodes. I mentioned in my previous post that this trick would work for subnodes existance check only.

Regards, Evgeniy.

anupam_ghosh2
Active Contributor
0 Kudos

Hi Ramesh,

                      If you are not using "creatIf" node function, still it should work.

The target field should have minimum occurrence value as zero. In case the source field is not coming in payload ideally it should not create the target. I guess what is happening in your case is that the source nodes are coming with blank values , in such case empty target node gets created. If you do not want to check for a blank value for each field, then only way to remove all blank nodes is java mapping for a nested structure with multiple segment.

Thus you need a java mapping after message mapping.

Can you upload a sample input/output and desired output xml structure so that forum can suggest java mapping for the same.

Regards

Anupam

former_member190543
Participant
0 Kudos

Hi Anupam,

Yes, the source is coming with empty nodes and with empty fields under it and it is creating empty target nodes which is failing in BAPI.

I will try Evgeniy's solution and if it doesn't work, then will post a question for UDF.

Thanks,

Ramesh.

former_member190293
Active Contributor
0 Kudos

Hi Ramesh!

You can use UDF for your requirement.

Take a look at Mark's decision. You can use the same approach with some modifications according to your needs.

Regards, Evgeniy.

former_member190543
Participant
0 Kudos

Hi Evgeniy,

The thread you provided is not relevant to my question as it was talking about list/context creation.

My issue is different.

Source:

<Parent BAPI Node>                     1..1

      <Node1>                                 0..1

            <Field1>abc</Field1>

            <Field2></Field>

      <Node2>                                 0..1

            <Field1></Field1>

            <Field2></Field>

</Parent BAPI Node> 

Target:

<Parent BAPI Node>                     1..1

      <Node1>                                 0..1

            <Field1>abc</Field1>

            <Field2></Field>

</Parent BAPI Node> 

Target Node2 should not be created if all the fields under it are empty.

Thanks,

Ramesh.

former_member190293
Active Contributor
0 Kudos

Hi Ramesh!

In that thread Mark describes UDF with DOM tree proccessing which can be used as the base for your own UDF. You can change the logic according to your needs, for example, loop through the child nodes and check for not empty value.