cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping XML to Flat File if XML Tag is not always there

Former Member
0 Kudos

Hello,

As I need to map from an IDOC into a flat file with fixed length using the graphical mapping, I face the problem that in IDOCs fields are not always filled. For a single field I can use the “exist” function and insert an empty string. In XI 2.0 this was not necessary and the system did that automatically now you have to put an “IF” around to see if that field exists or not and depending on the outcome use the field value or an empty string. My problem gets worse if you have to qualify the source record by a field in the same node. When you map into the flat structure you have to use the remove context function. I got it to work but doing that for a lot of fields sucks. Following is my graphical mapping:

Structure:

<SEG1>

<SEG2>

<LAND1>EN</LAND1>

<LOG>1</LOG>

</SEG2>

<SEG2>

<LOG>2</LOG>

</SEG2>

<SEG2>

<LAND1>EN</LAND1>

<LOG>3</LOG>

</SEG2>

</SEG1>

/ns0:SEG1/ITEM/ LAND1_0006=if ([]Constant ([value=DEE]) , equalsS ([]Constant ([value=]) , if ([]if([] if([] /HRMD_A06/IDOC/E1PLOGI/E1PITYP/E1P0006/LAND1 , exists([] /HRMD_A06/IDOC/E1PLOGI/E1PITYP/E1P0006/LAND1 ) , Constant ([value=])) , equalsS ([]/HRMD_A06/IDOC/ E1PLOGI/E1PITYP/E1P0006/ SUBTY , Constant ([value=1])) , Constant ([value=])) , exists ([]/HRMD_A06/IDOC/ E1PLOGI/E1PITYP/E1P0006) , Constant([value=]))) , /HRMD_A06/IDOC/E1PLOGI /E1PITYP/E1P0006/LAND1 )

Is there a java function or other method to create an empty source tag of <LAND1/> in my case. Any java code is appreciated. I can do the same in XSLT without any issue but the idea is to use the graphical mapping.

Thanks

Stefan

Accepted Solutions (0)

Answers (2)

Answers (2)

p_vanos
Active Participant
0 Kudos

Hi,

Unfortunately this problem is still not solved in the latest SP. I have created some flat files in the format of the IDOC file adapter in R/3 and had to do the same as stated above!

I used the EXIST function!

Cheers,

Paul

Former Member
0 Kudos

Hi,

have you solved this problem yet? Or does the PI 7.0 with SP 8 solve this problem? For now I have the same problem you had about one and a half year ago.

Thanks

Florian

Former Member
0 Kudos

Dear Stefan-

Have you tried the "CREATEIF" function in the graphical mapping tool? Also, do you always have to create an empty tag for <LAND1/> in your target structure? This would seem unnecessary unless it was a mandatory element in your DTD. Even then wouldn't you have to have a value?

Regards,

james

Former Member
0 Kudos

Hi James,

we need always the field for the outbound file adapter as the target file has fixed length therefore if the field is empty so is the field value in the flat file.

The CREATEIF works and I use it now but the graphical mapping gets more complicated to read therefore I was looking for an alternative but if there is nothing then so be it.

Thanks

Stefan

Former Member
0 Kudos

Dear Stefan-

Ok now I understand that you are generating a fixed length file. The CREATEIF seems to be the simplest way to generate the <LAND> tag. I could propose a few more alternatives, but it wouldn't make it easier to read! =P

What do you do in your XSLT to generate the tag <LAND>?

Also what would you pass to the fixed length file if there was no source value? Is this blanks?

Thanks, james

Former Member
0 Kudos

Hi James,

XSLT is the way to go for these kind of task as XI 3.0 is not good for that. XI 2.0 just created the empty tag as XSLT would do, e.g. you define the <LAND> tag and if no value comes it just creates an empty tag.

To not through away my graphical mapping I created a JAVA function zexists which check the queue and if I don't have the value it creates an empty tag. This works except if the whole IDOC segment is not created you have to check with an exists if the IDOC segemnt is there too. Then the graphical mapping is getting a pain.

Too bad SAP changed the way XI 2.0 worked not always an improvement.

Cheers

Stefan