cancel
Showing results for 
Search instead for 
Did you mean: 

remove header and footer from sender file

former_member290264
Participant
0 Kudos

Hello Experts,

I am working on scenario file to file, but I need to remove header and footer from the file and then send to ECC system. below is the file.

Input file:

START-OF-FILE
RUNDATE=20171016
PROGRAMFLAG=oneshot
FIRMNAME=dlftp
COMPRESS=yes
FILETYPE=pc
REPLYFILENAME=ravi.csv
PROGRAMNAME=getdata


# Automatically generated by ZDemo_File Request Builder version 7.0.0
# Build Code: 010000000100000101


START-OF-FIELDS
PX_LAST
END-OF-FIELDS


TIMESTARTED=Mon Oct 16 09:39:43 EDT 2017
START-OF-DATA
TWDHKD Curncy|0|1|09/27/2017|0.2576|
TWDJPY Curncy|0|1|09/27/2017|3.721|
USDAED Curncy|0|1|09/27/2017|3.6729|
USDAFN Curncy|0|1|09/27/2017|68.2723|
USDAOA Curncy|0|1| | |
USDARS Curncy|0|1|09/27/2017|17.5629|
USDAUD Curncy|0|1|09/27/2017|1.2741|
USDAZN Curncy|0|1|09/27/2017|1.6976|
USDBAM Curncy|0|1|09/27/2017|1.6646|
USDBDT Curncy|0|1|09/27/2017|82.1875|
EURAUD Curncy|0|1|09/27/2017|1.4963|
END-OF-DATA
TIMEFINISHED=Mon Oct 16 09:39:47 EDT 2017
END-OF-FILE


output file:

TWDHKD Curncy|0|1|09/27/2017|0.2576|
TWDJPY Curncy|0|1|09/27/2017|3.721|
USDAED Curncy|0|1|09/27/2017|3.6729|
USDAFN Curncy|0|1|09/27/2017|68.2723|
USDAOA Curncy|0|1| | |
USDARS Curncy|0|1|09/27/2017|17.5629|
USDAUD Curncy|0|1|09/27/2017|1.2741|
USDAZN Curncy|0|1|09/27/2017|1.6976|
USDBAM Curncy|0|1|09/27/2017|1.6646|
USDBDT Curncy|0|1|09/27/2017|82.1875|
EURAUD Curncy|0|1|09/27/2017|1.4963|

please suggest me how can I achieve it using FCC ??

Thanks,

Ravi

Accepted Solutions (1)

Accepted Solutions (1)

Former Member

Hi Ravi;

Can you examine the following java mapping.

package example;


import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import com.sap.aii.mapping.api.*;


import java.io.*;
import java.util.Scanner;


public class XMLGenerator extends AbstractTransformation {


	@Override
	public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput)
			throws StreamTransformationException {


		try {


			InputStream inputstream = transformationInput.getInputPayload().getInputStream();
			OutputStream outputstream = transformationOutput.getOutputPayload().getOutputStream();
			DocumentBuilderFactory document = DocumentBuilderFactory.newInstance();
			DocumentBuilder docBuilder = ((DocumentBuilderFactory) document).newDocumentBuilder();
			Document doc = docBuilder.newDocument();
			BufferedReader inpfile = new BufferedReader(new InputStreamReader(inputstream));
			doc.setXmlStandalone(true);
			Element docRoot = doc.createElement("ns0:Example");
			docRoot.setAttribute("xmlns:ns0", "http://example/test");
			doc.appendChild(docRoot);


			String line;
			int i = 0;


			while ((line = inpfile.readLine()) != null)


			{
				if (i >= 21) {
					if (line.contains("END-OF-DATA")) {
						break;
					}


					Scanner rd = new Scanner(line);


					while (rd.hasNext()) {
						Element item = doc.createElement("item");
						docRoot.appendChild(item);


						Element input = doc.createElement("input");
						input.appendChild(doc.createTextNode(line));
						item.appendChild(input);


						break;
					}
				}
				i++;
			}


			TransformerFactory.newInstance().newTransformer().transform(new DOMSource(doc),
					new StreamResult(outputstream));


		} catch (Exception exception) {
			getTrace().addDebugMessage(exception.getMessage());
			throw new StreamTransformationException(exception.toString());
		}


	}


}



Regards

Hasan

Muniyappan
Active Contributor

Good java code.

Ravi can enhance the java mapping little further, there are many ways to do it. below one will make it dynamic.

instead of putting if condition if(i>=21)

we ca set the flag true when it finds "START-OF-DATA" and loop, once it finds END-OF-DATA, exit the loop.

former_member290264
Participant
0 Kudos

hello Hasan,

Great work.

But is there any way to do this with File Content Conversion ???

former_member190293
Active Contributor

And furthermore: instead of using memory consuming DOM for just adding the nodes to result document, I would use StringBuilder to compose the string representing result XML.

Regards, Evgeniy.

Muniyappan
Active Contributor

Yeah. easy way to construct xml manually.

or here the expectation is to create flat file, so one can just put lines into StringBuilder, and then into OutputStream. it creates the flat file and can save doing FCC in receiver side.

Muniyappan
Active Contributor

if you are looking to achieve using FCC, then read the sender file, line by line, filter the records in the message mapping. construct the output xml and then do the FCC.

https://blogs.sap.com/2005/08/16/configuring-generic-sender-file-cc-adapter/

former_member190293
Active Contributor

Yes, you're absolutely right. Even FCC isn't required in such case. Just to write output payload directly to target file.

Regards, Evgeniy.

Former Member

Hi Ravi;

You can refer to the following example.Besides you can use Module configuration.

Mapping;

Receiver File Content Configuration;

Regards
Hasan

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

You can use Document offset to remove the header. But this will work only when fixed number of lines are there in the header else it may remove some data lines also.

Regards

Jitender

former_member290264
Participant
0 Kudos

Hi Jitendra,

I have fixed number of line in the header.

But I need to remove last 3 lines as well.