cancel
Showing results for 
Search instead for 
Did you mean: 

String map with IDOC

former_member260907
Participant
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

baskar_gopalakrishnan2
Active Contributor
0 Kudos

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.

 

 

former_member260907
Participant
0 Kudos

Thanks, Baskar for providing the sample. I toke this sample as my java mapping.

baskar_gopalakrishnan2
Active Contributor
0 Kudos

Very Welcome.  You might want to look at the code template if you need it for module development.

Answers (2)

Answers (2)

anupam_ghosh2
Active Contributor
0 Kudos

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

former_member260907
Participant
0 Kudos

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

baskar_gopalakrishnan2
Active Contributor
0 Kudos

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.

former_member260907
Participant
0 Kudos

Sorry, Baskar,

I thought he is going to give me the java mapping code.Since I never made java mapping, I would like to see the java mapping template. I was too lazy. I can find it online and fill in the code. I am closing.

Cheers!

Charles

baskar_gopalakrishnan2
Active Contributor
0 Kudos

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.

anupam_ghosh2
Active Contributor
0 Kudos

Hi Charles,

               The sample target XML can be easily achieved by java mapping code.

Do you still need it ? Please let me know. You can reopen your threads if your question is not answered (or start a new one).

Regards

Anupam

former_member184681
Active Contributor
0 Kudos

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

former_member260907
Participant
0 Kudos

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

former_member184681
Active Contributor
0 Kudos

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

former_member260907
Participant
0 Kudos

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

baskar_gopalakrishnan2
Active Contributor
0 Kudos

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?

former_member184681
Active Contributor
0 Kudos

I've just configured an identical scenario and it seems to work just fine:

Header.fieldSeparator|
Header.endSeparator|
Header.fieldNamesField1, Field2, Field3, Field4, Field5
Header.keyFieldValueHeader_field1
Item.fieldSeparatorI
Item.endSeparatorI
Item.fieldNamesField1, Field2, Field3
Item.keyFieldValueItemfield1

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.

former_member260907
Participant
0 Kudos

Thanks, Greg for taking time on my case. Unfortunately, The Header and Item don't have the keys. I am going to build a customized adapter module to do this.

Charles