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: 

Excel File Format Problem while downloading in ALV Grid

Former Member
0 Kudos

Hi All,

My program gives an ALV Grid Output which contains the file download button , when I choose spread sheet as the file format , the actual data starts only from 4th line and the lines above it contain date, heading etc and the rest are blank. Is it possible that I can download only the records in the grid output with the column names and not the unnecessary log?

Also the format is not proper excel format, this same file will be used for upload into another program using the Function Module 'TEXT_CONVERT_XLS_TO_SAP'. When I load the file saved in the above format, this Function Module always fails.

Please let me know any solution for this problem

Thanks in Advance.

9 REPLIES 9

Former Member
0 Kudos

Installing SAP GUI Patch Level 8.

0 Kudos

Hi ,

Problem should be identified as Garbage values in Excel. There is a SAP note avaliable for this .

Which will be implemented when you will install SAP GUI patch level 8 on your machine.

This will surely resolve your issue.

Thanks

Former Member
0 Kudos

Hi Dagny ,

Use XML Transformations to download ALV data to Excel and use FM

'ALSM_EXCEL_TO_INTERNAL_TABLE' to upload data from Excel to SAP.

Regards,

Suneel G

Former Member
0 Kudos

The data which comes in the beginning is not junk data, even if we downloda from SE16, those lines appear, the lines for example are :

31.03.2009 Dynamic List Display 1

The first line is the above line, followed by two blank lines, then comes the column names, then again a blank line ( I do not want this blank line too ), then comes the actual data.

Hope this is clear. Are you talking about this data only ? Will it can be avoided by installing the patch you have mentioned?

Please let me know .

Thanks in Advance.

0 Kudos

This FM ''ALSM_EXCEL_TO_INTERNAL_TABLE' ' needs to specify the Begin and End column and Row which is not possible in our case as we do not know the amount of data in the excel file.

Former Member
0 Kudos

Hi,

For using this function module: 'TEXT_CONVERT_XLS_TO_SAP'

You have to declare:




TYPE-POOLS truxs.

DATA: it_raw TYPE truxs_t_text_data.
*      internal table declared to be passed in the
*      function module used to convert data from xls to sap

*&---------------------------------------------------------------------*
*&Function module called to upload xls data into an internal table
*&---------------------------------------------------------------------*

  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
      i_field_seperator    = 'X'
      i_line_header        = 'X'
      i_tab_raw_data       = it_raw
      i_filename           = p_file                 "file path browsed
    TABLES
      i_tab_converted_data = it_upload[]            "int table populated
    EXCEPTIONS                                             with data
      conversion_failed    = 1                      
      OTHERS               = 2.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.


Hope it helps

Regards

Mansi

0 Kudos

Mansi,

I know how to use the TEXT_CONVERT_XLS_TO_SAP FM. My problem is not how to use this FM. Please read my first question.

Thanks.

Former Member
0 Kudos

Hi

try this code----


&----


*& Form DOWNLOAD_EXCEL_TEMPLATE

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM download_excel_template .

TYPES: BEGIN OF lt_data,

field1(20),

field2(30),

field3(20),

field4(20),

field5(20),

field6(30),

field7(15),

field8(10),

field9(10),

field10(20),

field11(20),

field12(10),

field13(20),

field14(20),

END OF lt_data.

DATA: lv_file TYPE rlgrap-filename,

li_data TYPE STANDARD TABLE OF lt_data,

wa_data TYPE lt_data,

lv_pathcheck type c,

lv_file1 type string.

wa_data-field1 = ''.

APPEND wa_data TO li_data.

REFRESH gi_header.

wa_header-name = 'Company Code'.

APPEND wa_header TO gi_header.

wa_header-name = 'Main Asset Number'.

APPEND wa_header TO gi_header.

wa_header-name = 'Asset Sub Number'.

APPEND wa_header TO gi_header.

wa_header-name = 'Document Date'.

APPEND wa_header TO gi_header.

wa_header-name = 'Posting Date'.

APPEND wa_header TO gi_header.

wa_header-name = 'Asset Value Date'.

APPEND wa_header TO gi_header.

wa_header-name = 'Item Text'.

APPEND wa_header TO gi_header.

wa_header-name = 'Reference'.

APPEND wa_header TO gi_header.

wa_header-name = 'Allocation'.

APPEND wa_header TO gi_header.

wa_header-name = 'Amount Posted'.

APPEND wa_header TO gi_header.

wa_header-name = 'Percentage Rate'.

APPEND wa_header TO gi_header.

wa_header-name = 'Quantity'.

APPEND wa_header TO gi_header.

wa_header-name = 'Prior-Yr Quantity'.

APPEND wa_header TO gi_header.

wa_header-name = 'Curr-Yr Quantity'.

APPEND wa_header TO gi_header.

lv_file = gv_file.

lv_file1 = gv_file.

CALL METHOD cl_gui_frontend_services=>directory_exist

EXPORTING

directory = lv_file1

RECEIVING

result = lv_pathcheck

EXCEPTIONS

cntl_error = 1

error_no_gui = 2

wrong_parameter = 3

not_supported_by_gui = 4

OTHERS = 5.

FIND '.xls' IN lv_file IGNORING CASE.

IF sy-subrc = 0.

REPLACE '.XLS' IN lv_file WITH ' ' IGNORING CASE.

ENDIF.

FIND '.TXT' IN lv_file IGNORING CASE.

IF sy-subrc = 0.

REPLACE '.TXT' IN lv_file WITH ' ' IGNORING CASE.

ENDIF.

CALL FUNCTION 'MS_EXCEL_OLE_STANDARD_DAT'

EXPORTING

file_name = lv_file

data_sheet_name = 'DATA'

TABLES

data_tab = li_data

fieldnames = gi_header

EXCEPTIONS

file_not_exist = 1

filename_expected = 2

communication_error = 3

ole_object_method_error = 4

ole_object_property_error = 5

invalid_pivot_fields = 6

download_problem = 7

OTHERS = 8.

IF sy-subrc <> 0.

MESSAGE ID gv_msgid TYPE 'E' NUMBER 002.

ENDIF.

ENDFORM. " DOWNLOAD_EXCEL_TEMPLATE

regards,

Prashant

Former Member
0 Kudos

You may directly download your internal table into excel with the FM:

SAP_CONVERT_TO_XLS_FORMAT

Then your FM 'TEXT_CONVERT_XLS_TO_SAP' should work fine.