• Post category:BI Publisher
  • Post comments:0 Comments
  • Post last modified:March 21, 2021
  • Reading time:3 mins read
You are currently viewing How to skip the blank line at the end of the output file using etext
How to skip the blank line at the end of the output file using etext
- How to skip the blank line at the end of the output file using etext
Total Visits: 14

In this article we will look into skipping the blank line at the end of output file using etext template.

If you are new to etext template, please check the previous articles on it.

https://fusionhcmknowledgebase.com/2020/04/etext-template-tips-and-tricks-part-1/

https://fusionhcmknowledgebase.com/2020/04/etext-template-tips-and-tricks-part-2/

https://fusionhcmknowledgebase.com/2020/04/how-to-test-the-etext-templates/

By default the etext template generates a blank line at the end of output file if you have noticed it or not.

In most of the cases you will not face an issue as the blank line won’t be visible and most of the third-party vendors ignore any blank lines.

However, you could face an issue with banks/some third-party vendors as they expect the file to be without blank lines at the end.

We will look at a solution on how to get that done using etext template.

Logic to skip blank line at end of file

Newline character gets added after each line due to the new line character that will be mentioned at the starting of the etext template.

image 6 - How to skip the blank line at the end of the output file using etext

Now, we will have to make this new record character blank and add the new line character explicitly at the end of each record and skip it for the last record (we will create a sequence to check for the last line). That’s the approach that we are going to follow.

First we will make the new line character as blank in the template section.

image 26 - How to skip the blank line at the end of the output file using etext

Next, we will create a sequence to reset at the root level which is DATA_DS. We will use this sequence to count the number of rows in XML file and skip the explicit newline character while writing the last line to the output file.

image 14 - How to skip the blank line at the end of the output file using etext

Once the sequence is set, we need to store the row count in a variable using the expression

AddToVar(‘G_1_COUNT’, COUNT(G_1))

But the caveat is like once we use this as part of an attribute it will also print the value of that count on the output file. To avoid this, we will write an if condition and just add the attribute but not print anything on the output file. The final condition will be like:

If AddToVar(‘G_1_COUNT’, COUNT(G_1)) > 0 then ‘’

Once the variable is initialized, we will explicitly add the chr(13) at the end of each record to get the new line on the output file.

And for the final record we can use the syntax as:

If SEQUENCE_NUMBER(Record_Count)=GetVar(‘G_1_COUNT’) THEN ‘’ ELSE Chr(13)

Here we are checking if the sequence number is equal to the total count of rows on G_1 and if yes, we aren’t sending the new line character to the ouput..

eText template with logic:

Sample XML File:

image 24 - How to skip the blank line at the end of the output file using etext

Sample Output File without blank at the end:

image 25 - How to skip the blank line at the end of the output file using etext

Download Template, XML, and Output:

eText TemplateDownload Now

XML FileDownload Now

Output FileDownload Now