cancel
Showing results for 
Search instead for 
Did you mean: 

File to Idoc : Java Mapping

Former Member
0 Kudos

Hi Experts,

The scenario is file to idoc. In the file i'll be getting name,value pairs. For ex:

Structure is

MT

....Root(1..unbounded)

............Name

............Value

File contains:

Vishal....1

Raj.........2

.

.

.

RFC......10

.

.

.

Rahul.....20

Azhar....15 and so on..

I need to loop through the file. When Name="RFC", I need to make an RFC call with Value as it's input. RFC returns 4 values which will be used for mapping.

Then I need to continue looping through the file. On encountering a particular Name, I need to map corresponding Value to target field.

For this, I should have 2 mappings. One to read the file and the other for mapping. I've never used RFC and Java mapping, Can someone provide me a link or a solution for this?

Thanks,

Vishal

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

Have not checked your requirement deeply.Just providing you some links for Java Mapping

/people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-i

/people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-ii

/people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-iii

Former Member
0 Kudos

I dont think there is any such parameter in file content conversion to ignore first and last line .

I suggest you read all the lines just ignore first and last line in the mapping .

for a complete list of parameters you can use with sender file content conversion refer [http://help.sap.com/saphelp_nw70/helpdata/en/2c/181077dd7d6b4ea6a8029b20bf7e55/content.htm]

refer this link for rfc lookup for beginners

http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/70d90a91-3cf4-2a10-d189-bfd37d9c3231&override...

Former Member
0 Kudos

After fcc, the (input)structure looks like..

<?xml version="1.0" encoding="utf-8" ?>

<ns:MT_HUWHS_Source xmlns:ns="http://abc.com/sap/xi/trng/xyz/03">

<Record>

<Value>0062 296818_132269</Value>

</Record>

</Record>

<Value>0052 S</Value>

</Record>

<Record>

<Value>0054 93A</Value>

</Record>

<Record>

<Value>0051 UN</Value>

</Record>

</ns:MT_HUWHS_Source>

The above structure will be input to mapping.

1:First I need to separate Name and Value from <Value>. First 4 characters in <Value> is Name and rest belong to Value.

2:Based upon Name(If Name=0052) map the corresponding Value to target (IDoc) node.

How can I acheive it? I've never used Java mapping. Please suggest..

Regards,

Vishal

former_member190389
Active Contributor
0 Kudos

Hi,

You can do this using a UDF.

first let the source message contain first line and last line which you want to eliminate.

change the context of the Value to MT ..

start a for loop in UDF ignoring first & last line like

for(int i = 1; i< input.length() - 1; i++) // here i = 1 & not zero & input length is -1 so that first & last field eliminates

{

//carry on string operation to separate name & value on delimeter space

String name = input<i>.subString(0,.... to the indexOf space);

//similar for value also....

now you have name & value

check for name == 0052

if(name == 0052)

{

perform rfc lookup

}

else

.....

}

Former Member
0 Kudos

Thanks for you suggestion. Is it done before converting java.io.InputStream to java.lang.String or after it?

Regards,

Vishal

former_member190389
Active Contributor
0 Kudos

This is not java mapping .

It is a simple UDF (User defined function ) in which you can invoke the RFC lookup

Former Member
0 Kudos

I think I've not clearly stated my requirement.. It's a very complex mapping with many conditions to arrive at an intermediate structure.. Basically, I am using Java mapping to create an intermediate structure..

Intermediate structure looks something like this:

MT

...Header

.............Order

..Item

.............Code

.............Identify

.............Number

.............Quantity

I need to arrive at the above structure based upon certain conditions..

Please guide how I can modify the below code to arrive at the above structure:

Element root = docout.createElement("MT");

root.setAttribute("xmlns:ns","urn:Test_File_to_File");

docout.appendChild(root);

Element header = docout.createElement("Header");

Element item=docout.createElement("Item");

How do I create child elements for Header and Item?

Thanks,

Vishal

former_member190389
Active Contributor
0 Kudos

Hi,

Instead of using DOM to create XML you can use SAX parsing method.

For ans example you can consider this ..

http://www.brics.dk/~amoeller/XML/programming/saxexample.html

this will be much easier for you.

Edited by: Progirl Progirl on Sep 3, 2009 1:42 PM

Former Member
0 Kudos

Thanks

JaganMohan
Participant
0 Kudos

Dear Vishal,

I think you are using DOM4J. So, for creating child element for that "Header" and "Item" nodes you can use as follows:

Element val = name.addElement("Order");

Here using "val" you can set the value for that element. Please go through the following you can get clear idea.

/people/venkataramanan.parameswaran/blog/2006/12/12/java-mapping-to-handle-flat-files-in-sap-xi

Regards,

JP.

Former Member
0 Kudos

Hi Vishal,

There is no need of a Java mapping, so relax. You can handle this situation in a graphical mapping itself.

In your graphical mapping, create an RFC look-up and retrieve the data. You may use second graphical mapping in which the input will be the output from the first mapping.

Let us know if you face more roadblocks.

regards,

Neetesh

Former Member
0 Kudos

Hi,

Thanks for all your suggestions. I've one more requirement. Before Name,Value pairs in the file, there's a line in the file which I need to eliminate. How do i do that? I've not tried the RFC solution yet. So I might come up with few more doubts!!

Regards,

Vishal

Former Member
0 Kudos

For Ex:

The file contains:

This is the start of file ..................................<I need to eliminate this line for getting Name,Value pair XML structure>

Vishal....1

Raj.........2

.

.

.

RFC......10

.

.

.

Rahul.....20

Azhar....15 and so on..

Similarly I need to eliminate the last line. Can I do it in fcc?

Former Member
0 Kudos

For Ex:

The file contains:

This is the start of file ..................................I need to eliminate this line for getting Name,Value pair XML structure

Vishal....1

Raj.........2

.

.

.

RFC......10

.

.

.

Rahul.....20

Azhar....15 and so on..

Similarly I need to eliminate the last line. Can I do it in fcc?

Former Member
0 Kudos

HI Vishal,

You can use a RFC Lookup in your graphical mapping. You need to create a UDF in your mapping

Also use an IF condition to check for your Name node. On RFC value use UDF and else map value tag to value.

The below forum is dedicated to RFC lookup. First have a look @ the pdf provided there.

For any further help please inform.

Regards,

Rahul

Former Member
0 Kudos

Hi Vishal,

Parse the flat file using java mapping and convert that to XML structure and then you can play around in graphical mapping.

To perform java mapping you need to import the package com.sap.aii.mapping.api.StreamTransformation

Regards

Harsha Paruchuri