Skip to Content
avatar image
Former Member

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

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

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    Apr 09, 2010 at 01:27 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 12, 2010 at 07:57 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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.