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: 

" Can not interpret the data in file " error while uploading the data in DB

Former Member
0 Kudos

Dear All ,

After running the below report I am getting the " Can not interpret the data in file " error.

Need to upload the data in DB through excel or .txt file.

Kindly advise to resolve the issue.

REPORT ZTEST_4.

data : it like ZPRINT_LOC occurs 0 with header line,

FILETABLE type table of FILE_TABLE,

wa_filetable like line of filetable,

wa_filename type string,

rc type i.

CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG

CHANGING

FILE_TABLE = filetable

RC = rc.

IF SY-SUBRC = 0.

read table filetable into wa_filetable index 1.

move wa_filetable-FILENAME to wa_filename.

Else.

Write: / 'HI'.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

start-of-selection.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = wa_filename

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

TABLES

DATA_TAB = it.

IF SY-SUBRC = 0.

Write: / 'HI'.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

insert ZPRINT_LOC from table it.

if sy-subrc = 0.

commit work.

else.

rollback work.

endif.

Regards

Machindra Patade

Edited by: Machindra Patade on Apr 9, 2010 1:34 PM

11 REPLIES 11

Former Member
0 Kudos

If you are uploading an Excel file, you will have to use a FM such as ALSM_EXCEL_TO_INTERNAL_TABLE rather than GUI_UPLOAD to upload the file.

Rob

0 Kudos

Dear

This FM is not available in XI 7.0 -- Kindly advise further..

Regards

Machindra Patade

0 Kudos

Hi Use the FM: TEXT_CONVERT_XLS_TO_SAP to upload excel files.

Check the sample code in below:

DATA: st_raw_data TYPE truxs_t_text_data.

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP' " Upload from excel file

EXPORTING

i_tab_raw_data = st_raw_data

i_filename = p_path

TABLES

i_tab_converted_data = i_data

EXCEPTIONS

conversion_failed = 1

OTHERS = 2.

IF sy-subrc EQ 1.

WRITE: / 'File could not be opened while uploading the data'.

EXIT.

ENDIF.

IF sy-subrc EQ 2.

WRITE: / 'Error while uploading the data'.

EXIT.

ENDIF.

0 Kudos

Dear Rajesh

This FM ( 'TEXT_CONVERT_XLS_TO_SAP' ) is also not available in SAP PI 7.0 stack. Advise another way.

Regards

Machindra Patade

0 Kudos

Then use the class method: CL_GUI_FRONTEND_SERVICES=>GUI_UPLOAD to upload the data from presentation server.

You can upload only text files here and also from presentation server only.

0 Kudos

Dear All Experts,

is there any other options in PI 7.0 to upload the excel file in SAP DB through ABAP ?.

Regards

Machindra Patade

Former Member
0 Kudos

Hello,

I ve made use of the same class-method for upload of an excel and works perfectly fine for me.

On cross-checking it looks like it might be a filename type mismatch issue,

the FILETABLE-FILENAME field returned from FILE_OPEN_DIALOG method is of type CHAR with length 1024 ,

whereas the FILENAME fieldname in GUI_UPLOAD is of type string.

So, suggestion is to declare a variable of type STRING and move the FILETABLE-FILENAME value to it.

Give it a shot and let me know.

-- Dedeepya C

0 Kudos

Dear

Pls share the sample sourse code for reference to work it out. Thanks for the same.

Regards

Machindra Patade

0 Kudos

data : lc_file type string, gcc_marked type c value 'X'.
field-symbols : <fs_tab> type standard table.

assign <table_name> to <fs_tab>.

lc_file = <filename returned from FILE_OPEN_DIALOG'

CALL METHOD cl_gui_frontend_services=>gui_upload
    EXPORTING
      filename                = lc_file
      filetype                = 'ASC'
      has_field_separator     = gcc_marked
   * IMPORTING
   *   filelength              = li_lngth
   *  header                  = lc_header
    CHANGING
      data_tab                = <fs_tab>
    EXCEPTIONS
      file_open_error         = 1
      file_read_error         = 2
      no_batch                = 3
      gui_refuse_filetransfer = 4
      invalid_type            = 5
      no_authority            = 6
      unknown_error           = 7
      bad_data_format         = 8
      header_not_allowed      = 9
      separator_not_allowed   = 10
      header_too_long         = 11
      unknown_dp_error        = 12
      access_denied           = 13
      dp_out_of_memory        = 14
      disk_full               = 15
      dp_timeout              = 16
      not_supported_by_gui    = 17
      error_no_gui            = 18.

As u see there isn't much of a coding done here. Check if ur missing something.

Regards

Dedeepya

0 Kudos

U got any luck yet in working it out Machindra?

If so please close this thread.

-- Dedeepya C

0 Kudos

Dear dedeepya reddy,

Not able to upload the excel but have sucess to upload the .csv file to db through the below code. Thanks for your advise.

REPORT ZTEST_3.

----


  • internal table declaration

----


*

DATA: itab TYPE STANDARD TABLE OF ZPRINT_LOC,

wa LIKE LINE OF itab,

wa1 like line of itab.

----


  • variable declaration

----


DATA: v_excel_string(2000) TYPE c,

v_file LIKE v_excel_string VALUE 'C:\Documents and Settings\devadm\Desktop\test.csv', " name of the file

delimiter TYPE c VALUE ' '. " delimiter with default value space

----


  • read the file from the application server

----


OPEN DATASET v_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc NE 0.

write:/ 'error opening file'.

ELSE.

WHILE ( sy-subrc EQ 0 ).

READ DATASET v_file INTO wa.

IF NOT wa IS INITIAL.

append wa TO itab.

ENDIF.

CLEAR wa.

ENDWHILE.

ENDIF.

CLOSE DATASET v_file.

EXEC SQL.

TRUNCATE TABLE "ZPRINT_LOC"

ENDEXEC.

*------display the data from the internal table

LOOP AT itab into wa1.

WRITE:/ wa1-mandt,wa1-zloc_code,wa1-zloc_desc,wa1-zloc,wa1-zstate.

ENDLOOP.

insert ZPRINT_LOC from table itab.