cancel
Showing results for 
Search instead for 
Did you mean: 

Extract whole content of a txt file to single field in source

Former Member
0 Kudos

Hi all,

I have a file to HTTp scenario.Input is a txt file.Can i extract whole content of the txt file to single field in source, Map this field into a single field in target and post it into a target URl?

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi Anoop,

You can do this using XSLT mapping.

XSLT source:

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

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:p2="namespace">

<xsl:template match="/">

<AnoopTargetFiled>

<xsl:text disable-output-escaping="yes"><![CDATA[]]></xsl:text>

<xsl:copy-of select="/"/>

<xsl:text disable-output-escaping="yes"><![CDATA[]]></xsl:text>

<xsl:text disable-output-escaping="yes"><![CDATA[>]]></xsl:text>

</AnoopTargetFiled>

</xsl:template>

</xsl:stylesheet>

1.Copy the above source is txtpad and save it as source.xsl and zip it

2.import the Zipped xsl into your Imported archives

3.source DT can be anything,Make your taget DT with one element and name the element as

AnoopTargetFiled and give your namespace in xsl.

4.In Terface Mapping select souce and target INterfaces >read interfaces>select XSL as you mapping program and select you xsl there.

5.Finish.you will get whole XML into your single element in target.

Thanks

Prabhakar

Edited by: VenkataPrabhakar Teegavarapu on Nov 21, 2008 10:19 AM

prasad_ulagappan2
Contributor
0 Kudos

If you want to use the XI then develop the file to file scenario and pick up the file as it is and without any content conversion transfer the file to the destination.

For file to file scenario, refer to this weblog.

- File to File Part 1

- File to File Part 2

For the same file name as source refer to following weblog.

Till SP14,

After SP14, you can use following.

Former Member
0 Kudos

Hi....

Once check this below wiki. It might be helpful to you.

https://www.sdn.sap.com/irj/sdn/wiki?path=/display/xi/readInputTextFileasaSingle+Field

Regards,

Leela

Former Member
0 Kudos

Hi,

If you know the number of fileds at design time, you can concat all the fields and pass it to one target field.

If you r using PI7.1, you can do it easily using Variable in message mapping

Regards,

Sreenivas.

Former Member
0 Kudos

Hi sreenivas,

My input is a text file.I cant alter its current structure and concatente that.

former_member190389
Active Contributor
0 Kudos

You can use an adapter module to create a XML structure like

<Record >

<Row>

<Field>Entire ..Content<Field>

</Row>

</Record>

this sequence will then be passed to your similar looking source message.

Or else if your file contains new line as the last character (or any other like * ! # etc)

then you can do FCC to fetch the entire content in single row

Field.endSeparator = 'nl'

Edited by: Progirl Progirl on Oct 31, 2008 1:41 PM

Edited by: Progirl Progirl on Oct 31, 2008 1:42 PM

Former Member
0 Kudos

Hi progirl,

I dont know how to create an adapter module.Can I know what should i do and what code i should write for this?

santhosh_kumarv
Active Contributor
0 Kudos

Hi Anoop,

Follow my wiki [Read Input Text File as a Single Field.|https://wiki.sdn.sap.com/wiki/display/XI/ReadInputTextFileasaSingle+Field.]

Happy to see the wiki I created jus before an hour got already posted in a reply by leela.

Thanks

SaNv..

Former Member
0 Kudos

Hi Santhosh,

Thanks for that but now the problem is i dont have NWDS(netweaver development studio).so let me get it installed and then i have one more requirement along with this.

My output payload should be as shown below.

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

- <MT_TRG xmlns:ns="urn:Test_File_to_File">

<filename>input.txt</filename>

<stringinp>This is a test scenariothat is created to answer a FAQ in the SDN Forum.</stringinp>

</MT_Trg>

ie I should be also able to include my source file as a target field as shown in payload.What should i do for that?

Former Member
0 Kudos

Hi,

If we want to get the Input file name Details into Target Payload message..

Ex:

I/P File name is :::::231004.xml

O/P File will look like

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

- <ns0:MT_target xmlns:ns0="http://test.test.com">

- <Header>

<Name_1>giri</Name_1>

<File_Name_1>231004.xml </File_Name_1>

</Header>

</ns0:MT_target>

http://img240.imageshack.us/my.php?image=udfib4.jpg

You should capture the Source File name into Target Message.

1)Write One UDF & Map Like Constant(u201Cu201D)---UDF----FileName_1

2)Check the ASMA Parameters in Sender Adapter Alone

3)No need to check the check box ASMA in the receiver side

UDF Code:

DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

//for getting filename

DynamicConfigurationKey key1 = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");

/*similarly for getting Directory,filetype, filesize you need to specify in the above code instead of filename */

String FileName = conf.get(key1);

return FileName;

Regards

Seshagiri

Former Member
0 Kudos

Hi Seshagiri,

I have a text file at sender side.it is not having a definite structure.I want its filename and also its content as fields in target payload.So I want filename and then in another single field below filename entire content of a file(this is because i cant alter with the sender side txt file).Is it possible.Otherwise is there any option that in the header of the target receiver HTTP adapter i dynamically get the Filename of the source file without doing anything to the source file?

Former Member
0 Kudos

HI Santhosh,

I downloaded NWDS.But while compiling the code I am getting an error

package com.sap.aii.mapping.api does not exist.

import com.sap.aii.mapping.api.StremTransformation;

Can you help me out in what should i do .How can i import that package.Guide me please

former_member194786
Active Contributor
0 Kudos

Hi Anoop,

While creating your class you need to import this interface. Also in the menu Project-> Properties-> Java build path-> Libraries, you need to import the following jar files as External Jars:

aii_map_api.jar

aii_msg_runtime.jar

aii_proxy_xirt.jar

aii_utilxi_misc.jar

Thanks and Regards,

Sanjeev.Project

Former Member
0 Kudos

Hi all,

I got the package and the code compiled fine.But When i tried implementing as Santhosh has said I am getting an error as below.Can you tell me how to rectify that?

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>

- <!--

Request Message Mapping

-->

- <SAP:Error xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SOAP:mustUnderstand="">

<SAP:Category>Application</SAP:Category>

<SAP:Code area="MAPPING">LINKAGE_ERROR</SAP:Code>

<SAP:P1>xmlpayload</SAP:P1>

<SAP:P2>test:urn:test_file_to_file</SAP:P2>

<SAP:P3>d4224370-e154-11dc-94cd-c763ac1383c5</SAP:P3>

<SAP:P4>-1</SAP:P4>

<SAP:AdditionalText />

<SAP:ApplicationFaultMessage namespace="" />

<SAP:Stack>Incompatible class versions (linkage error)</SAP:Stack>

<SAP:Retry>M</SAP:Retry>

</SAP:Error>

How can i rectify this?

Former Member
0 Kudos

Hi,

Check this

Regards

Seshagiri

Former Member
0 Kudos

Hi Sheshagiri,

As I mentioned My input is a txt file without any proper structure.I have to read this text file into a single field then map this to a single target field?I want to know whether this is possible or not?

Can you give me inputs on this