cancel
Showing results for 
Search instead for 
Did you mean: 

IDOC to Flat file scenario

Former Member
0 Kudos

Hi

I am mapping from a IDOC to a flat structure.

Source side segments can repeat - based upon some other criteria like highest date - mapping is done to the target fields.

Problem is - sometimes the IDOC tags for some fields on which I have mapping - is not present - as in Source SAP - this field is blank.

In the mapping - sort by key is failing - as date field ( key) and the source field might be different in queue length - in such cases where source side xml tag is missing.

I know - node function if exists is there - and a empty tag can be created if case xml tag is missing - but I can not use that as a lot of context is used. I really can not go to the lowest context to check if that field is present or not.

Does anybody have any quick java code for creating empty tags if not present or any other solution for this problem?

Accepted Solutions (0)

Answers (6)

Answers (6)

Former Member
0 Kudos

Hi Bhavesh,

Normally mapWithDefault would work .

But as from my message above, I have already tried this and this does not work if we are using mapWith Default, Context changes , Sort by key for a particular field.

Need to sort based on values on a higher context.

Empty nodes cause an issue as Queues have different lengths.

Also, mapWithDefault has to be applied to every field. There should be a better way if you have 100s of fields on the source message.

Empty tags (nodes) should be added (filled) in one go for all fields.

Hoping a quick response.

Thanks,

Sudhin

Former Member
0 Kudos

Hi,

This is not working .

If the node is not in source XML / deleted, then this UDF does not work.

However, what I'm looking for is an empty tag/node to be generate d(by java mapping / UDF) so that I do not get exceptions in mapping.

Cheers

bhavesh_kantilal
Active Contributor
0 Kudos

Why dont you use MAPWITHDEFAULT?

The MAPWITHDEFAULT wil check if the source field exists and if it does not exists , it will map the default value to the target and you can create a blank value as the default value.

So an empty value will be created in the target as per need.

Regards

Bhavesh

Former Member
0 Kudos

Hi-

Try this

public String Check(String str){

if (str == null)

return "XXXX";

else

return str;

}

Here str is the string you are getting from Idoc

XXX is the value which you want to assign if the field is empty.

Let me know if you want any further help in this

Former Member
0 Kudos

Hi Sai / Satish,

Thanks for your input.

Unfortunately - if the Tag is not present at all in the source side - these UDFs are not returning tags

I want the an empty tag to be populated for all source fields where the tag do not exists.

Tried exists , map with default etc - no avail. Probably java mapping is the solution

Please help

Thanks

Sudhin

Former Member
0 Kudos

Sudhin,

You write this UDF at context level with input 'a' and 'b'. This function checks whether a particular value is present in a context. If it is present then a value 'true' is passed, otherwise false

boolean found = false;

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

if (a<i>.equals(b[0])) {

found = true;

break;

}

}

if (found == true)

result.addValue("true");

else

result.addValue("false");

---Satish

Former Member
0 Kudos

Hi

a is the input string, Use a simple UDF

public String Check(String a,Container container){

if (a==null)

return "";

else return a;

}

Regards,

Sai