cancel
Showing results for 
Search instead for 
Did you mean: 

Keep leading zeroes when we write to CSV File

Former Member
0 Kudos

Hi Experts, For Example My Source Field  ---AAAAA------datatype v(13)-- has value 01234567891, when i write to csv file  and when i open the file in Xl, it looses the leading zero Any Suggesion for not loosing the leading zero Thanks

Accepted Solutions (1)

Accepted Solutions (1)

former_member187605
Active Contributor

Is the sole purpose of your csv file to visualise its content in Excel?

If you use a comma or a semicolon as the field separator, you can precede the field contents by a tab: insert a non-printable ascii x09 in front of its value by mapping it to chr(9)||source_fiield in your Query transform.

Former Member
0 Kudos

Hi Dirk, Thanks for responding, can you give me with an example, i did not understand My Source Field is AAAA - DATATYPE V(13)- source value is 012345678 Thanks

former_member187605
Active Contributor
0 Kudos

In the mapping of AAAA, put:

     chr(9)||AAAA

Former Member
0 Kudos

Thanks Firk, it worked I have one more question Is it by default  chr(9) for any datatype of length or any calculation

Former Member
0 Kudos

Sorry for typo error of name

former_member187605
Active Contributor
0 Kudos

It works fine for any string you want to keep leading zeroes in.

afafpatel
Explorer
0 Kudos

Hi Direk,

Will it work for DS too if we want to store leading zeros while extraction data from SAP source?

Answers (1)

Answers (1)

Former Member
0 Kudos

Uhdam,

You are not losing your leading zero. The problem is that you are opening your file in Excel which strips the leading zeroes. You can view your data using a text editor like notepad and you should be able to view the leading zeroes.

If you want to view your data in Excel, use the steps mentioned in the link below to open your csv file.

How can I keep leading zeros in CSV files?

-Chaitanya

Former Member
0 Kudos

Thanks Chaitanya for your effort, I have seen this solution in google, but i want to automate the job, when users go and click on the CSV file they should be able to see the leading zeroes without going to any option as per the link Thank

Former Member
0 Kudos

The best I can think of if you have to have this, then you can add a single quote at the start of your data. For e.g: define your datatype as varchar and include a single quote so that the data looks like '012345. The problem with this is that when the user opens the Excel file, he will be viewing the data with the extra single quote.