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

TEXT_CONVERT_CSV_TO_SAP return empty

Former Member
0 Likes
3,795

Hi,

I tried to use the above FM but itab (it_csv) returned at I_TAB_CONVERTED_DATA is empty. My code as follow. it_raw is empty and excel_file contain the path to the CSV file on application server. My CSV file contains rows of data. Please advise.

CALL FUNCTION 'TEXT_CONVERT_CSV_TO_SAP'

EXPORTING

I_FIELD_SEPERATOR = ','

I_TAB_RAW_DATA = it_raw

I_FILENAME = excel_file

TABLES

I_TAB_CONVERTED_DATA = it_csv

EXCEPTIONS

CONVERSION_FAILED = 1

OTHERS = 2

.

11 REPLIES 11
Read only

Former Member
0 Likes
2,456

Hi,

use the function module TEXT_CONVERT_XLS_TO_SAP to uploas EXCEL FILE TO INTERNAL ATBLE.

DATA : l_file TYPE string,

it_raw TYPE truxs_t_text_data.

l_file = pfname.

--


function module to upload excel to 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 = pfname

TABLES

i_tab_converted_data = it_upload[] " INTERNAL TABLE

EXCEPTIONS

conversion_failed = 1

OTHERS = 2.

IF sy-subrc NE 0.

MESSAGE 'Error in uploading file' TYPE 'E'.

ENDIF.

Rgds

Siva

Read only

Former Member
0 Likes
2,456

you can also use GUI_UPLOAD. its works perfectly fine with .CSV

Read only

Former Member
0 Likes
2,456

I am not working with Excel file but CSV. I tried GUI_UPLOAD too, it_raw is returned empty. My code using GUI_UPLOAD looks like the following. Anything wrong with my code? I get sy-subrc = 0.


        CALL FUNCTION 'GUI_UPLOAD'
          EXPORTING
            FILENAME                        = up_file      "path to CSV file
          TABLES
            DATA_TAB                        = it_raw
         EXCEPTIONS
           FILE_WRITE_ERROR                = 1
           NO_BATCH                        = 2
           GUI_REFUSE_FILETRANSFER         = 3
           INVALID_TYPE                    = 4
           NO_AUTHORITY                    = 5
           UNKNOWN_ERROR                   = 6
           HEADER_NOT_ALLOWED              = 7
           SEPARATOR_NOT_ALLOWED           = 8
           FILESIZE_NOT_ALLOWED            = 9
           HEADER_TOO_LONG                 = 10
           DP_ERROR_CREATE                 = 11
           DP_ERROR_SEND                   = 12
           DP_ERROR_WRITE                  = 13
           UNKNOWN_DP_ERROR                = 14
           ACCESS_DENIED                   = 15
           DP_OUT_OF_MEMORY                = 16
           DISK_FULL                       = 17
           DP_TIMEOUT                      = 18
           FILE_NOT_FOUND                  = 19
           DATAPROVIDER_EXCEPTION          = 20
           CONTROL_FLUSH_ERROR             = 21
           OTHERS                          = 22
                  .

Read only

0 Likes
2,456

hi,

check this,

GIVE file type DAT

DATA : pfname1 TYPE string.

pfname1 = pfname.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = pfname1

filetype = 'DAT'

has_field_separator = ' '

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

  • VIRUS_SCAN_PROFILE =

  • NO_AUTH_CHECK = ' '

  • IMPORTING

  • FILELENGTH =

  • HEADER =

TABLES

data_tab = itab

  • 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

  • OTHERS = 17

.

IF sy-subrc <> 0.

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

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

ENDIF.

Rgds

siva

Read only

0 Likes
2,456

DATA : XFILE TYPE STRING.

XFILE = FILE.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = xfile

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

TABLES

DATA_TAB = t_upload.

Read only

0 Likes
2,456

I amended as follows, but still get empty it_csv.


        CALL FUNCTION 'GUI_UPLOAD'
          EXPORTING
            FILENAME                      = up_file
            FILETYPE                      = 'DAT'
            HAS_FIELD_SEPARATOR           = ' '
          TABLES
            DATA_TAB                      = it_csv
         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
           OTHERS                        = 17
                  .

Read only

0 Likes
2,456

try the way i have given before. I have recently worked on it and it works perfectly fine

Read only

0 Likes
2,456

Priti, it works, but it puts the whole row into a column. I need it to be separated by comma on different column. Did you manage to do that?

Read only

0 Likes
2,456

Hi Try this way. <li>File to be uploaded.

CGH;6703000002;1
CGH;6707100006;1
<li>program

REPORT ztest_notepad.
TYPE-POOLS:truxs.
DATA: raw_data TYPE truxs_t_text_data.
DATA: BEGIN OF it_nfal OCCURS 0,
        einri TYPE nfal-einri,
        falnr TYPE nfal-falnr,
        falar TYPE nfal-falar,
      END OF it_nfal.

START-OF-SELECTION.
  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename = 'C:\Documents and Settings\Administrator\Desktop\nfal.txt'
      filetype = 'ASC'
    TABLES
      data_tab = raw_data.

  CALL FUNCTION 'TEXT_CONVERT_CSV_TO_SAP'
    EXPORTING
      i_field_seperator    = ';'
      i_tab_raw_data       = raw_data
    TABLES
      i_tab_converted_data = it_nfal.

  LOOP AT it_nfal.
    WRITE:/ it_nfal.
  ENDLOOP.
Thanks Venkat.O

Read only

0 Likes
2,456

I need comma separated, not semicolon. The FM only works for semicolon??

Read only

0 Likes
2,456

Hi, my problem is solved by using GUI_UPLOAD then split by comma.