Application Development and Automation 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: 
Read only

Dowload itab into excel

Former Member
0 Likes
2,661

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
Read only

Former Member
0 Likes
2,379

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
Read only

Former Member
0 Likes
2,379

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

Read only

Former Member
0 Likes
2,379

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

Read only

Former Member
0 Likes
2,380

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.

Read only

0 Likes
2,379

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

Read only

0 Likes
2,379

Hi,

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

Read only

0 Likes
2,379

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.

Read only

0 Likes
2,379

Priti,

Use Ws_Download instead.

refer:

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

Amit.

Read only

0 Likes
2,379

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

Read only

0 Likes
2,379

Hi,

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

This will help.

Regards,

Prashant

Read only

Former Member
0 Likes
2,379

Hi Priti,

The same topic has been discussed in this thread.

Regards,

Chandra Sekhar

Read only

Former Member
0 Likes
2,379

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..

Read only

0 Likes
2,379

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.

Read only

Former Member
0 Likes
2,379

hi

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

Cheers

Snehi

Read only

Former Member
0 Likes
2,379

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

Read only

Former Member
0 Likes
2,379

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

Read only

Former Member
0 Likes
2,379

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.

Read only

Former Member
0 Likes
2,379

Hi,

Use FM WS_EXCEL to download internal table data into excel.

Regards,

Rajneesh Gupta