Search code examples
spreadsheetabapole

Read spreadsheet data with cell length > 32 characters into itab


I am trying to read an Excel file into my internal table with cell values longer than 32 characters. I am using the function KCD_EXCEL_OLE_TO_INT_CONVERT to read the files in. I have tried copying the function module and table using SE37 and SE80, but it will not let me save the table with a value named ROW. Is there a better function module I'm not seeing or is there a way I can make a Z_ copy of the table and FM to allow me to change the length of the value column in a kcde_cells formatted table? My program works doing everyting except reading in the 33rd and beyond characters, so I know the rest of the functionality is fine. I just need to get the length of the read in value to be longer to accommodate longer cell contents.

Edit: Adding the code I used to upload the file.

CALL FUNCTION 'KCD_EXCEL_OLE_TO_INT_CONVERT'
    EXPORTING
      filename                = infile  "Input file.
      i_begin_col             = st_col
      i_begin_row             = st_row
      i_end_col               = e_col
      i_end_row               = e_row
    TABLES
      intern                  = ttab "Internal table for storing the Excel data.
    EXCEPTIONS
      inconsistent_parameters = 1
      upload_ole              = 2
      OTHERS                  = 3.
  IF sy-subrc <> 0.
    FORMAT COLOR COL_BACKGROUND INTENSIFIED.
    WRITE:/ 'Error Uploading file'.
    EXIT.
  ENDIF.

  IF ttab[] IS INITIAL.       "Internal table is empty.
    FORMAT COLOR COL_BACKGROUND INTENSIFIED.
    WRITE:/ 'No Data Uploaded'.
    EXIT.
  ELSE.
    SORT ttab BY row col.
    LOOP AT ttab.
      MOVE ttab-col   TO index.
      ASSIGN COMPONENT 'ROW'   OF STRUCTURE itab TO <fs>.
      MOVE ttab-row   TO <fs>.
      ASSIGN COMPONENT 'COL'   OF STRUCTURE itab TO <fs>.
      MOVE ttab-col   TO <fs>.
      ASSIGN COMPONENT 'VALUE' OF STRUCTURE itab TO <fs>.
      MOVE ttab-value TO <fs>.
      APPEND itab.
      CLEAR itab.
    ENDLOOP.
  ENDIF.

Solution

  • As I stated in similar question , use FM FILE_READ_AND_CONVERT_SAP_DATA. It allows reading cells with the length up to 256 characters.