Leading zeros in downloaded excel

Hi,
I'm facing a problem with truncated leading zeros in downloaded excel. Can anybody suggest me how to get those leading zeros in excel.
I tried Function modules XXL_FULL_API and WS_DOWNLOAD, both did not work.
Regards,
Praveena

Hi Praveena,
check the following code.
data : begin of itab occurs 0,
         matnr  like mara-matnr,
         maktx  like makt-maktx,
         matnr2 like mara-matnr,
       end of itab.
itab-matnr  = '00000011111'.
itab-maktx  = 'test1'.
itab-matnr2 = '00000011112'.
append itab.
itab-matnr  = '00000033333'.
itab-maktx  = 'test2'.
itab-matnr2 = '00000044444'.
append itab.
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
  BIN_FILESIZE                  = ' '
  CODEPAGE                      = ' '
    FILENAME                      = 'D:\c.xls '
    FILETYPE                      = 'WK1'
  MODE                          = ' '
  WK1_N_FORMAT                  = ' '
  WK1_N_SIZE                    = ' '
  WK1_T_FORMAT                  = ' '
  WK1_T_SIZE                    = ' '
  COL_SELECT                    = ' '
  COL_SELECTMASK                = ' '
  NO_AUTH_CHECK                 = ' '
IMPORTING
  FILELENGTH                    =
  TABLES
    data_tab                      = itab
  FIELDNAMES                    =
EXCEPTIONS
  FILE_OPEN_ERROR               = 1
  FILE_WRITE_ERROR              = 2
  INVALID_FILESIZE              = 3
  INVALID_TYPE                  = 4
  NO_BATCH                      = 5
  UNKNOWN_ERROR                 = 6
  INVALID_TABLE_WIDTH           = 7
  GUI_REFUSE_FILETRANSFER       = 8
  CUSTOMER_ERROR                = 9
  NO_AUTHORITY                  = 10
  OTHERS                        = 11
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
        WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Regards,
nagaraj

Similar Messages

  • Need leading Zeros in the excel sheet which is sent from ABAP

    Hi ,
    I am downloading data from SAP to excel sheet using the WS_DOWNLOAD Function Module. The numeric data in not having leading zeros.  if it is 0010 it is displaying 10 in the excel sheet . i need the leading zeros in the excel sheet. without manulally changing it to Text in the excel sheet .
       Is there any way to do it .
    Thanks,
    Chetan

    Hi Chetan,
      CALL FUNCTION 'WS_DOWNLOAD'
        EXPORTING
          filename                = w_file_path
          filetype                = 'DBF'                       "declare the File type as DBF then leading zeros will appear
          write_field_separator   = 'X'
          confirm_overwrite       = 'X'
        TABLES
          data_tab                = Itab.
    Regards,
    Prabhudas

  • Display of leading zeroes when downloaded from ALV to excel

    Hi All,
    I have a problem in ALV grid display.
    There is a specific field which has value starting from '001' to '999'. This is a char(3) type of variable.
    The problem is that the display shows the value as '001' which is correct. but when the same file is dwnloaded to excel using standard SAP functionality, the value of the field gets changed to '1' instead of '001'.
    Is there any option by which this can be controlled. Please let me know, its urgent!!
    thanks

    hi Ankur,
    the Excel download is done by Z program? IF yes you have to do:
       SET PROPERTY OF go_cell 'NumberFormat' = '@'.
    this will set the Excel cell to Text type and leading zeros won't be lost.
    ec

  • Leading zeroes dropped in Excel

    Hello folks
    I've got an issue with using downloading data onto an Excel file using the FM GUI_Download. The leading zeroes of the PERNR field get truncated when opening the file with MS Excel.
    However the zeroes are in place when the downloaded file is opened with notepad or any other text editor.
    Is there any solution to prevent Excel from dropping the leading zeroes.
    I'm currently using tab as the field separator, and have defined the PERNR field as TYPE C at the internal table used for populating and displaying the data.

    Hi,
    data:matnr(20) type c.
    concatenate text-001 g_t_ekpo-matnr into g_t_ekpo-matnr.
    text-001 is having '.
    I had declared the Matnr as type c so that it can accomodate that single quote.It is indeed downloading the matnr with preceeding zeroes into the excel but along with the single quote.Can't we get the preceeding zeroes into excel without the single quote into the excel.
    Thanks,
    Kiran.

  • How to retain leading zeros in an excel sheet

    Hi,
    In my application I need to export the response from a struts action class to an excel sheet. I have done the coding but while exporting to the excel , the leading zeros are getting truncated. If the value is '01' it is displayed as '1' only.
                    response.setContentType("application/text");
                             response.setHeader("Content-disposition",
                                       "Attachment;filename=\"export.xls\"");
                             response.getOutputStream().println(data);
                             response.getOutputStream().flush();This is the code which I am using to export all the data to the excel.Here the variable data is a String .
    Kindly help on this issue.
    Thanks in advance...
    Edited by: 2569 on Jan 10, 2008 8:59 PM
    Edited by: 2569 on Jan 10, 2008 9:51 PM

    2569 wrote:
    I tried that way also, but its not working. I have defined all the values as strings only. Thanks for ur replyWhich API are you using to write excel files? You can try to surround the numeric string value with singlequotes (or escaped doublequotes)String numericString = "'01'";so that Excel interprets it as string.

  • Download records to EXCEL file with  Leading Zero's for numbers

    Hi All,
    I am able to download the data to EXCEL file on the presentation server.
    There are few fields (Plant,SalesOrder Number ..with Leading Zero's) in the record.
    These values are downloaded with out Leading Zero's to excel( EX: 0000004122 as 4122).
    Please help me to download the data to EXCEL file with leading zero's.
    Thanks and Regards,
    KC

    >
    Krishna Chaitanya  G wrote:
    > The excel file which is to be downloaded..will be used by some other program..to upload the values to the sap.
    > It matters there....
    > KC
    HI KC,
    then no need to download the zeros,
    after uploading, loop at that uploaded internal table and use CONVERSION_EXIT_APLHA_INPUT and pass the vbeln(without zeros) to this FM, it will return the value with added zeros.
    hope this solves your query
    a small example
    Loop at itab into is.
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
    EXPORTING
    INPUT = is-vbeln "(  this is without zeros)
    IMPORTING
    OUTPUT = is-vbeln. "( this is with leading zeros)
    modify itab from is.
    endloop.
    Edited by: Soumyaprakash Mishra on Oct 6, 2009 2:16 AM

  • Leading zeroes are being suppressed in excel output

    I have a template that prints our item number field. This field is alpha-numeric, but sometimes it is all numeric with leading zeroes. I have it defined as a text field in my template. It prints correctly (with the leading zeroes) in the PDF output, but it suppresses the leading zeros in the excel output. Is there any way to stop it from doing this - I want it to be a text field.

    Thanks. That sort of works. In the excel output, it is truncating the field after the first 4 digits even though the length is defined as 'unlimited'. In the PDF output, it prints the double quotes around the field.

  • Leading zeros are removed when uploading excel

    Hi All,
    I have created a program to send an email with an excel attachment but the leading zero's in excel are removed. can anybody suggest what can be done other than replace since that exceeds 255chars so i cant concatenate.

    Hi
    Try adding the character ' (single quote) before the actual value. Excel then treats the value as-is whithout conversion
    character type for columns
    data: h_columns        TYPE ole2_object,
          h_cell           TYPE ole2_object.
    CALL METHOD OF excel 'Columns' = h_columns
      EXPORTING
        #1 = 'F:K'.
    set property of h_columns 'NumberFormat' = '@'.
    CALL METHOD OF excel 'Cells' = h_cell
      EXPORTING
        #1 = 14
        #2 = 7.
    SET PROPERTY OF h_cell 'Value' = '0001'.

  • Grid Download to Excel truncates leading zeros

    We are on tools 8.51. The download feature for a Grid now removes the leading zeros when the grid is downloaded to excel. Has anyone found a way to fix this issue ? Thanks in advance

    When you download from PS query, the output is created as a true binary xls file, but when you download from a grid in PT 8.51 the output file is html, even though the filename is ps.xls. You can open this file in a text editor.
    If you have all numeric data in a column, it will be stored as <td>nnnnnn</td> in the html file. if the column has mixed numeric and text data, it will be stored as <td>=&amp;quot;nnnnnn&amp;quot;</td>. The leading zeroes are still there in both cases, but when excel imports the first form it will convert the result to numeric, the second it will treat as text.
    Other than logging a case with Oracle, the only workaround I could think of would be to save the file to disk and run the macro directly against the html. Of course, this would likely be a major redesign.
    Regards,
    Bob

  • Download to Excel" function cuts off leading zeros in string

    When a text column contains leading zeros for example "000250" the download to Excel stores the string as "250" in the spreadsheet
    I am unable to find a log about this
    thanks Muthanna

    1) Click on the fx button of the column in question. Enter this:
    '<span style="display:none">&nbsp</span>' ||  columnname Between the double quotes, type display:none
    2) Click on the Data Format tab and change the type to HTML.
    Edited by: David_T on Sep 14, 2010 8:25 AM
    (Edited to make the instructions clearer.)
    Edited by: David_T on Sep 14, 2010 9:54 AM

  • Cuts off leading zeros in a report column when "Download to Excel" function

    Hello
    When a text column contains leading zeros for example "000250" the download to Excel stores the string as "250" in the spreadsheet. I am using a column which is a string.(varchar)
    Can somebody suggest me , how to go ahead with it
    Thanks
    Edited by: user647228 on Sep 11, 2008 1:40 PM
    Edited by: user647228 on Sep 11, 2008 1:42 PM

    (To Vins) Actually, concatenating a space doesn't do it. When the file is downloaded into Excel, the leading space is ignored and it the leading zeroes are still trimmed.
    To user647228: A non-space character needs to be concatenated. Regarding what character to append, I would give the following consideration: If the users are content with seeing an added character to the "number," you can append say an underscore "_" and Excel will download the number properly. It's fairly unobtrusive and can be "visually ignored."
    If the end user insists on gettin rid of the extra character once the file is downloaded, I would append a character that is rarely, if not never, used in the report. (This ensures or mitigates replacing other instances of the character.) Then you can do a Replace All in Excel to replace the extra character with a single apostrophe. The single apostrophe will be interpreted by Excel to mean "text" and the appearance will change to exactly what is desired.
    Note: Replacing the extraneous character with a space for example, will result in the leading zeroes being again lopped off by Excel...

  • Leading zeros deleted while downloading to excel sheet

    Hi ,
    i am downloading data to excel sheet  from internal table, iam using gui_download but its deletin leading zeros can any one tell me as to how i go about this
    for ex i ahve a mterial no : 00123
    i see 123 i want it to be 00123
    Thanks
    kajol

    Hi,
      try to explain to excel, that this field is character field (I think that it will be done by adding single quote as first character of string).
    Pointing to my previous answer try:
    Constants: c_single_quote(1) type c value ''''.   " I _hope_ it works
    loop at itab.
    concatenate c_single_quote itab-matnr to texttab-c_matnr.
    endloop.

  • Excel Download of ALV with one column containing leading zeros

    Hello Experts,
    I have the requirement in which the first column is of type company code (T001-BUKRS). So if the company code is '0061', then on the ALV display its displayed as '0061', but when it is downloaded to Excel sheet, it shows '61' in place of '0061'.
    Is there any way we can display in the downloaded Excel as 0061?
    Any pointers could help.
    Regards,
    Mansi.

    Hi Mansi,
    I think its because of excel property.You can format cell of excel to category 'special'.
    regards
    vivek

  • Truncation of leading Zeros when Down Loading into Excel - OLE Objects

    Hi,
    Can any one help me on this.
    I am using <b>OLE Objects</b> to download Data into Excel Sheet. Data with leading Zeros is getting truncated in Excel.
    Ex: Report Output is showing Plant Number as 0002. But when i am downloading to Excel Plant value will become 2 .
       I would like to have it as 0002 in Excel.
    I have declared Werks as CHAR of 4.I am using OLE Obects for Downloading into Excel Sheet.
    I am using "OLE2_OBJECT" I can not use any other FMs to down load to Excel.As i am modifying this program not creating.
    Thanks In Advance.
    K.Nirmala
    Message was edited by: Nirmala Reddy

    Hi Nirmala,
    While downloading to excel sheet, u need to change the number format of cell from General to Text, then leading zero's won't get deleted. For that u need to set the property of the cell. Please check this sample code,
    INCLUDE OLE2INCL.
    tables : zobrent.
    data : it_kna1 type table of zobrent with header line.
    handles for OLE objects
    DATA: H_EXCEL TYPE OLE2_OBJECT,        " Excel object
          H_MAPL TYPE OLE2_OBJECT,         " list of workbooks
          H_MAP TYPE OLE2_OBJECT,          " workbook
          H_ZL TYPE OLE2_OBJECT,           " cell
          H_F TYPE OLE2_OBJECT.            " font
    DATA  H TYPE I.
    DATA: cell1 TYPE ole2_object.
    *&   Event START-OF-SELECTION
    START-OF-SELECTION.
      select * from zobrent into table it_kna1
               where zopanid = '10001'
                and zo_brent = '050'.
    start Excel
      CREATE OBJECT H_EXCEL 'EXCEL.APPLICATION'.
      PERFORM ERR_HDL.
      SET PROPERTY OF H_EXCEL  'Visible' = 1.
    get list of workbooks, initially empty
      CALL METHOD OF H_EXCEL 'Workbooks' = H_MAPL.
      PERFORM ERR_HDL.
    add a new workbook
      CALL METHOD OF H_MAPL 'Add' = H_MAP.
      PERFORM ERR_HDL.
    output column headings to active Excel sheet
      PERFORM FILL_CELL USING 1 1 1 'EDate'.
      PERFORM FILL_CELL USING 1 2 1 'Brent'.
      PERFORM FILL_CELL USING 1 3 1 'Zopanid'.
      PERFORM FILL_CELL USING 1 4 1 'Contract Type'.
      PERFORM FILL_CELL USING 1 5 1 'Price Type'.
      PERFORM FILL_CELL USING 1 6 1 'Installation Type'.
      PERFORM FILL_CELL USING 1 7 1 'Volume'.
      PERFORM FILL_CELL USING 1 8 1 'AQ'.
      PERFORM FILL_CELL USING 1 9 1 '00000123'.
      LOOP AT IT_KNA1.
    copy values to active EXCEL sheet
        H = SY-TABIX + 1.
        PERFORM FILL_CELL USING H 1 0 IT_KNA1-zo_effdat.
        PERFORM FILL_CELL USING H 2 0 IT_KNA1-zo_brent.
        PERFORM FILL_CELL USING H 3 0 IT_KNA1-zopanid.
      ENDLOOP.
      CALL METHOD OF h_excel 'Cells' = cell1
        EXPORTING
          #1 = 1
          #2 = 1.
      FREE OBJECT H_EXCEL.
      PERFORM ERR_HDL.
      if sy-subrc eq 0.
       write : / 'year'(001).
      endif.
         FORM FILL_CELL
    sets cell at coordinates i,j to value val boldtype bold
    FORM FILL_CELL USING I J BOLD VAL.
      CALL METHOD OF H_EXCEL 'Cells' = H_ZL EXPORTING #1 = I #2 = J.
      PERFORM ERR_HDL.
      GET PROPERTY OF H_ZL 'Font' = H_F.
      PERFORM ERR_HDL.
      SET PROPERTY OF H_F 'Bold' = BOLD .
      PERFORM ERR_HDL.
    ***Changing the format of the cell from General to Text
      <b>SET PROPERTY OF H_ZL 'NumberFormat' = '@'.</b>
      PERFORM ERR_HDL.
      SET PROPERTY OF H_ZL 'Value' = VAL .
      PERFORM ERR_HDL.
    ENDFORM.
    *&      Form  ERR_HDL
    FORM ERR_HDL.
    IF SY-SUBRC <> 0.
      WRITE: / 'Fehler bei OLE-Automation:'(010), SY-SUBRC.
      STOP.
    ENDIF.
    ENDFORM.                    " ERR_HDL
    U just paste this code in a sample program & see.
    Please reward, if found helpful.

  • Leading zeros from data downloads

    Hello!
    While downloading data from the ABAP tables, Excel removes the leading zeros automatically but in some SAP tables (NAST for example), those leading zeros are necessary to find the required associated data. Is there any way to prevent Excel from removing these zeros?
    Thanks a lot!

    Hi,
    There are two ways to solve it.
    1) select complete columns in the Excel sheet and then assign the number format as ' TEXT ' in the sheet.Then u ll be able to see the leading zero's
    2) If u donot want to wrk in Excel the way i have mentioned,then in the abap program just use the FM
    "CONVERSION_EXIT_ALPHA_INPUT" over that field before uploading in  a table.
    By mistake i have told u the wrong way.the first way is for copying the data from text file to excel file and preserving the leading zeros.
    regards
    kanishak
    Edited by: Kanishak Gupta on May 6, 2009 5:36 AM

Maybe you are looking for