cancel
Showing results for 
Search instead for 
Did you mean: 

FCC For csv WITHOUT new lines

laurent_fournier2
Contributor
0 Kudos

Hello to everybody,

I trying to do a file content conversion for the following file :

a;b;c;d;a;b;c;d;a;b;c;d

Problem :

file has 4 fields meaning that there is not a nl after each line . The correct file for instance have to be

a;b;c;d

a;b;c;d

a;b;c;d

Target structure :

line

field a

field b

field c

field d

line

field a

field b

field c

field d

etc...

is this achievable ?

just to be more clear :

The incoming csv file has all it's lines continuoysly : no new line after each record ..

Edited by: Laurent Fournier on Jan 20, 2011 2:13 PM

Accepted Solutions (1)

Accepted Solutions (1)

RaghuVamseedhar
Active Contributor
0 Kudos

Hi Laurent Fournier,

As you said, if your given a flat file containing "a;b;c;d;a;b;c;d;a;b;c;d" you will replace every 4th ";" with "new line". Then you want it to be converted into XML.

Now let's try to achieve the same using SAP PI. As Sender File FCC can not handle this situation, it should be handled in Adapter module or Mapping.

Let's do it in simple Java Mapping (as Graphical and XSLT can not handle non XML input).

package com.mapping;

import java.io.*;
import com.sap.aii.mapping.api.*;

public class SimpleJavaMapping_PI71 extends AbstractTransformation
{
	public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput) throws StreamTransformationException
	{
		try
		{
			InputStream inputstream = transformationInput.getInputPayload().getInputStream();
			OutputStream outputstream = transformationOutput.getOutputPayload().getOutputStream();

			byte[] b = new byte[inputstream.available()];
			inputstream.read(b);
			String strContent = new String(b);
			float fStrContent = strContent.length();
			int iCountColon = 0;
			StringBuilder strOutputContent = new StringBuilder();
			
			for (int i = 0; i < fStrContent; i++)
			{
				char cTemp = strContent.charAt(i);
				if (!";".equals(cTemp))
				{
					strOutputContent.append(cTemp);
				} else
				{
					if (4 != iCountColon)
					{
						strOutputContent.append(cTemp);
						iCountColon++;
					} else
					{
						strOutputContent.append(System.getProperty("line.separator"));
						iCountColon = 0;
					}
				}
			}

			outputstream.write(strOutputContent.toString().getBytes());
		} catch (Exception exception)
		{
			exception.printStackTrace();
		}
	}
}

You can also implement this logic in adapter module in sender channel and then use FCC to convert it into XML. Or you can implement above Java Mapping, followed by another Java Mapping to convert output of above code into XML using DOM parser.

Regards,

Raghu_Vamsee

laurent_fournier2
Contributor
0 Kudos

Dear Raghu,

Many many thanks for your answer.

Problem solved !

Former Member
0 Kudos

Hallo all,

Since its link talking about line separator in csv file, i would like to add a solution even though this is already solved.

I had solved it as follows:

Declaring a character variable as follows.

DATA: line_feed(1) TYPE c VALUE CL_ABAP_CHAR_UTILITIES=>CR_LF.

Concatenate it as the last character of your string.

CONCATENATE is_cont_text-line line_feed(1) INTO is_cont_text-line.

Answers (2)

Answers (2)

RaghuVamseedhar
Active Contributor
0 Kudos

Hi Laurent Fournier,

As far as I know, it cannot be handled in using FCC.

Let's keep SAP PI aside for some time.

a;b;c;d;a;b;c;d;a;b;c;d

should be converted into different records

a;b;c;d
a;b;c;d
a;b;c;d

Let's imagine, you are given the flat file and you are asked to insert new line to separate records. Now, you open the flat file using notepad, and based on what logic you are going insert new line (press Enter)? Are you going to count number of ; (or) number of characters (or) end element will always have some special character (or) starting element of record will have special character? If there is logic, we can use Java Mapping to generate target XML structure.

Regards,

Raghu_Vamsee

laurent_fournier2
Contributor
0 Kudos

The logic is that the columns of each line are lets say 4. Then, a new line must be somehow triggered after 4 columns. No special characters on beginning nor at the end, no fixed values anything.. . Just continuous fields exist on the file. Somehow, i must upload this file in XI and handle it. If any other options are available except fcc , please let me know.

Thanks !

former_member208856
Active Contributor
0 Kudos

In FCC, you need to give line separator, but you do not have any line separator.

You need to give some value for line separator in place of nl.

You can also use value of D as line separator, if it is fixed value, only at that time it is possible.

laurent_fournier2
Contributor
0 Kudos

Sorry,

No line separator neither fixed value on the last field of each line...

Is there any way to say to file content conversion that when it runs in the last field, automatically trigger a new node ?

As i understand, there is not a way to handle this kind of file ?

And how is it possible to make XI understand and handle this kind of files ?