Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Dowload itab into excel

Former Member
0 Kudos

I am using SAP_CONVERT_TO_XLS_FORMAT function module to download internal table into excel.

call function 'SAP_CONVERT_TO_XLS_FORMAT'

exporting

I_FIELD_SEPERATOR = SPACE

  • I_LINE_HEADER =

I_FILENAME = I_FILENAME

  • I_APPL_KEEP = ' '

tables

I_TAB_SAP_DATA = itab

  • CHANGING

  • I_TAB_CONVERTED_DATA =

  • EXCEPTIONS

  • CONVERSION_FAILED = 1

  • OTHERS = 2

.

if SY-SUBRC eq 0.

write 😕 'FILE DOWN LOAD SUCCESUFULLY' ,FULL_PATH.

endif.

The internal table "itab" has field vendor no. i.e. LIFNR having value say "0000000001" But when i download the file only "1" comes into the excel file , the leading zeroes do not come. I want those leading zeroes. how do i do it

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

EXCEL generally supress the leading zeroes. If you still want the leading zeroes you can have a add a ' infront of the field. '001 will be displayed in excel as 001.

Hope this helps.

17 REPLIES 17

Former Member
0 Kudos

hii

it will come as 1 only as it is a problem of EXCEL sheet ...

Have not used this FM but if you have defined FILE TYPE there as ASC then change it to DBF file.it will work.and leading 0 will come.

regards

twinkal

Former Member
0 Kudos

i think you cant do much about it.if you define field as string then its possible

Former Member
0 Kudos

Hi,

EXCEL generally supress the leading zeroes. If you still want the leading zeroes you can have a add a ' infront of the field. '001 will be displayed in excel as 001.

Hope this helps.

0 Kudos

But the internal table has many records i.e. many LIFNRs. How do i put ' in front of each record

0 Kudos

Hi,

You have to loop through the table and put ' and then download it .

0 Kudos

Yes i have already tried this. But ' is a special character. Then how do it add it.

e.g. begin of itab occurs 0,

lifnr like lfa1-lifnr,

end of itab.

suppose itab now has ten records. Now how do i put ' in front of the value.

0 Kudos

Priti,

Use Ws_Download instead.

refer:

https://www.sdn.sap.com/irj/sdn/profile?userid=3776643

Amit.

0 Kudos

Hi,

Use gui_download and pass file type DBF.

Sample code,

DATA:
  BEGIN OF itab OCCURS 0,
    lifnr LIKE lfa1-lifnr,            
  END OF itab.

  SELECT lifnr
    UP TO 5 ROWS
  FROM lfa1
  INTO TABLE itab.

  CHECK sy-subrc EQ 0.

  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      filename = 'C:\temp\test.xls'
      filetype              = 'DBF'   "File type DBF
*      write_field_separator = 'X'
*      append                = 'X'
    TABLES
      data_tab              = itab[].

Regards

Adil

0 Kudos

Hi,

Try using FM GUI_DOWNLOAD and pass the filetype as 'DBF'.

This will help.

Regards,

Prashant

Former Member
0 Kudos

Hi Priti,

The same topic has been discussed in this thread.

Regards,

Chandra Sekhar

Former Member
0 Kudos

in your internal table put ' (single qoute) before the vendor number, this will ensure when you pass this field to excel, excel wont remove leading zeros..

0 Kudos

But how do i put a ' in front of the vendor code. The internal table has many records. I am passing the internal table to the function module.

Former Member
0 Kudos

hi

refer to this link an similar problem like u have is being solve here

Cheers

Snehi

Former Member
0 Kudos

Hello Priti,

Your problem is not with the SAP, but with Excel. Even though you write 0000000001 in Excel it will display only 1. Try to work on the Excel sheet. Change the cell format to text format instead of Numeric.

Regards,

Naresh Durki

Former Member
0 Kudos

hii

i had same problem before.it is possible to have data with leading zeros in excel .for that you need to convert your all integer type data in to character type and then first save one blank .xls file and there give save as type dbf .then check .you will get data with leading zeros in excel sheet.

regards

twinkal

Former Member
0 Kudos

Hi Priti,

This field will download as '1' only. You need to make some file settings. After downloading the data, Select that column --> Right Click and select Format Cells --> Choose Text. This will solve the issue.

Regards,

Swapna.

Former Member
0 Kudos

Hi,

Use FM WS_EXCEL to download internal table data into excel.

Regards,

Rajneesh Gupta