on 2012 Mar 20 8:34 PM
Hi Expert,
I have a File to IDOC scenario. However, in the source file, there is only one long line of string. The string format like this:
Header_field1|Header_field2|Header_field3|Header_field4|Header_field5|Itemfield1|Itemfield2|Itemfield3|Itemfield1|Itemfield2|Itemfield3|Itemfield1|Itemfield2|Itemfield3|...
Header_field1, Header_field2, Header_field3, Header_field4, Header_field5 have to be mapped to correspond header fields in IDOC.
Itemfield1, Itemfield2,Itemfield3 which are occurred unbounded have to be mapped to correspond item fields in IDOC.
I think I have to use Java class in interface mapping or use customized adapter module to do this. Is there any java expert has java interface mapping template codes?
Thanks a lot in advance!
Charles
If you are not java programmer doing java mapping could be slightly difficult for you. But I can provide here the template which works very generic irrespective of the pattern values related to item and header comes in the file. Please see the attachment and tweak for populating.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Charles,
Could you please kindly post the exact sample of the input file you are receiving and exact target XML you need after mapping? Let me try with the java code.
Regards
Anupam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Anupam,
Thank you for stepping in to give me help. My input file will be like this (only one line string)
header1|header2|header3|header4|item11|item12|item13|item21|item22|item23|item31|item32|item33....
My target xml would be like this
<MT_Target>
<IDOC>
<HEADER>
<Target_HD1>header1</Target_HD1>
<Target_HD2>header2</Target_HD2>
<Target_HD3>header3</Target_HD3>
<Target_HD3>header3</Target_HD3>
</HEADER>
<ITEM>
<Target_IT1>item11</Target_IT1>
<Target_IT2>item12</Target_IT2>
<Target_IT3>item13</Target_IT3>
</ITEM>
<ITEM>
<Target_IT1>item21</Target_IT1>
<Target_IT2>item22</Target_IT2>
<Target_IT3>item23</Target_IT3>
</ITEM>
<ITEM>
<Target_IT1>item31</Target_IT1>
<Target_IT2>item32</Target_IT2>
<Target_IT3>item33</Target_IT3>
</ITEM>
......
<IDOC>
</MT_Target>
Thanks,
Charles
I already seen you closed this thread. Now it shows again reopened. This is simple explanation. You already have my code. The code retrieves Header values and Item values seperately in Vector object. You just need to construct target XML Using parser and use header vector to populate the values in constructed Header Segment and same procedure use item vector to populate in Item node repeatedly by reading only 3 values for every node occurence. Hope that helps.
The java mapping links for starters
http://techplay.plozzle.com/?p=21
https://wiki.sdn.sap.com/wiki/display/XI/Sample+JAVA+Mapping+code+using+PI+7.1+API
Note: Close the thread once your question is answered.
Hi Charles,
I think I have a neater solution for you, if only your scenario satisfies two conditions: there is only one occurrence of the header in the whole file, and the number of fields in each structure is constant. Use the file content conversion in the sender file channel, with the following parameters:
Recordset Structure: Header,1,Item,*
Header.fieldSeparator = |
Header.endSeparator = |
Header.fieldNames = Field1, Field2, Field3, Field4, Field5
Item.fieldSeparator = |
Item.endSeparator = |
Item.fieldNames = Field1, Field2, Field3
Then you can use a graphical mapping as usually, to map the source data to the desired IDoc format.
Hope this helps,
Greg
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Greg,
Thanks for response. However I tried, I got error says "Conversion of file content to XML failed at position 0: java.lang.Exception: ERROR converting document line no. 1 according to structure 'Header':java.lang.Exception: ERROR in configuration / structure 'Header.': More elements in file csv structure than field names specified!"
I think "Recordset Structure: Header,1,Item,*" means "read first line as Header, the rest lines are Item". So header line should only have 5 fields. Since it is a long string, it has much more than 5 fields.
Has this worked for you before? How did you make it work?
Charles
Dear Charles,
Honestly, I never had identical scenario before. Generally you do not have to use "new line" as a separator between different structures, it can be any string, so theoretically it should work fine as I described. My only concern is if you can use same character as both: fieldSeparator and endSeparator.
As a solution, try adding: Header.additionalLastFields = ignore and Item.additionalLastFields = ignore to your FCC configuration. This could potentially help.
If not, try one more thing: manually change one test file, changing the separator | to any other, say &, then adjust the FCC config: Header.endSeparator = & and Item.endSeparator = & and see if it works. If yes, then at least you are sure that same separator cannot be used...
By the way, is it possible to change the separator used by sender system?
Regards,
Greg
Hi Greg,
I made changes, added Header.additionalLastFields = ignore and Item.additionalLastFields = ignore. and tried again. I got the same error. Then I changed the end separator to & in source file and FCC config. Still got the same error. i don't know why the end separator doesn't work.
Thanks,
Charles
IMO, the recordset structure definition Recordset Structure: Header,1,Item * shows that the file contains single header line followed by multiple items lines. So you get this error. If you get the entire data in the single line then how do you differentiate with the fields of item with header?
I've just configured an identical scenario and it seems to work just fine:
Header.fieldSeparator | | |
Header.endSeparator | | |
Header.fieldNames | Field1, Field2, Field3, Field4, Field5 |
Header.keyFieldValue | Header_field1 |
Item.fieldSeparator | I |
Item.endSeparator | I |
Item.fieldNames | Field1, Field2, Field3 |
Item.keyFieldValue | Itemfield1 |
Unfortunately, you will have to use some keyFieldValue for each Recordset Structure, since you use the * occurrence. This might make your scenario inachievable, if you have no field to distinct between Header and Item. To my surprise, PI is not able to differentiate between Header and Item only based on the sequence (Recordset Sequence set to Ascending), field names and separators.
User | Count |
---|---|
66 | |
10 | |
10 | |
10 | |
10 | |
8 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.