Skip to Content

remove header and footer from sender file

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    avatar image
    Former Member
    Nov 10, 2017 at 01:42 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 10, 2017 at 10:56 AM

    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

    Add comment
    10|10000 characters needed characters exceeded