cancel
Showing results for 
Search instead for 
Did you mean: 

How to remove blank lines in plain text file

samantha_nez
Participant
0 Kudos

Hi experts,

We have implemented a test scenario to create a plain text file from a web service (scenario WS --> PI --> File). The customer wants the
file name is specified in a payload field, so that the file name is created dinamically based on this value.

For this, we have defined the following MT:

<PlainTextFile03>

     <FileName>

     <Struc1> (1..unbounded)

          <Field1>

          <Field2>

     </Struc1>

</PlainTextFile03>

Using variable substitution, the file is created with the right name based on ‘FileName’ value and the values of ‘Struc1’ are introduced (business data) with tab separator.

  

The file content conversion set up in receiver file adapter is as follows:

Recordset Structure: Struc1

Struc1.fieldSeparator: ‘0x09’

However, the file content is not totally correct because the first and last lines are blank lines (the ‘Struc1’ data is filled successfully). The
customer does not want blank lines, only data.

    

Current result:

  

(blank line)

Field1Value    Field2Value

Field1Value    Field2Value

...

(blank line)

Requeriment:

Field1Value    Field2Value

Field1Value    Field2Value

...

So, how can we remove the blanks lines to get the requeriment?

Thanks in advance,

Samantha.

Accepted Solutions (1)

Accepted Solutions (1)

former_member184720
Active Contributor
0 Kudos

Hi Samantha - why don't you go with dynamic configuration UDF to create the file name dynamically which should avoid that spaces too..

Dynamic file name and directory in Receiver File Adapter - summary of possibilities - Process Integr...

you can remove file name tag too..

explained the same thing under The Problem of using Variable Substitution: in the below blog -

Answers (2)

Answers (2)

former_member187010
Participant
0 Kudos

Hi Samantha,

Try this method, it is working fine for me. Change the structure as shown below

<PlainTextFile03>
     <FileNode>
          <FileName>
     <Struc1> (1..unbounded)
          <Field1>
          <Field2>
     </Struc1>
</PlainTextFile03>

In CC, Recordset structure: FileNode,Struc1

Then remove filenode while file creation using fixedLengthTooShortHandling define in http://help.sap.com/saphelp_nw04/helpdata/en/d2/bab440c97f3716e10000000a155106/content.htm

FileNode.fieldFixedLengths     0

FileNode.fixedLengthTooShortHandling     Cut

FileNode.endSeparator     '0'

Regards

Jitender

former_member184720
Active Contributor
0 Kudos

Why to add the field and remove it later with some additional configuration? moreover you are modifying the structure to make it work...

Rather it's very easy to handle it with dynamic configuration..

samantha_nez
Participant
0 Kudos

Thanks for your replies,


Both Jitender's workaround and with UDF as Haresh said, I am able to remove the first empty line, but not the last one getting this:

Field1Value    Field2Value

Field1Value    Field2Value

...

(blank line)

Using UDF and later parameter "Struc1.endSeparator" as '0', last blank line is removed, but data is written in only one line:

     Field1Value    Field2ValueField1Value    Field2Value...

Is it possible to remove this last empty line covering the requirement?

Thanks again,

Samantha.

former_member184720
Active Contributor
0 Kudos

Hi Samantha - Did you remove the field "FileName" from the structure? It should not add any spaces..

though the default end separator is line break.. may be try configuring manually with 'nl' instead of '0'

samantha_nez
Participant
0 Kudos

Hi Hareesh,

In my source structure I mantain the "FileName" field to map it using dynamic configuration UDF, but in the target structure not (target MT only has business data):

Target MT:

     <PlainTextFile03>

          <Struc1> (1..unbounded)

               <Field1>

               <Field2>

          </Struc1>

     </PlainTextFile03>

If I use 'nl' in endSeparator, new line is always introduced after each line, so I get again a final empty line.

Thanks,

Samantha.

former_member184720
Active Contributor
0 Kudos

Hi Samantha - I don't think so.. Please compare your FCC configuration with the below blog..

XI/PI: File Content Conversion for Simple Structure

samantha_nez
Participant
0 Kudos

Hi Haressh,

I checked that blog again, but I get the last empty line...

For the target MT:

     <PlainTextFile03>

          <Struc1> (1..unbounded)

               <Field1>

               <Field2>

          </Struc1>

     </PlainTextFile03>

the FFC set up:

     Recordset structure     PlainTextFile03,Struc1

     PlainTextFile03.fieldSeparator     'nl'

     Struc1.fieldSeparator                    '0x09'

     Struc1.endSeparator                    'nl'

Thanks again,

Samantha.

iaki_vila
Active Contributor
0 Kudos

Hi Samantha,

Check if this thread is helpful: https://scn.sap.com/thread/629387

As Haresh said you can avoid blanks lines a mapping level, later you can control the extra blank lines having care with the endseparator parameter.

Regards.