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: 

Uploading excel to internal table

Former Member
0 Kudos

Hi all,

I have requirement, where I need to upload an excel file

containing fields of type STRING(very long character i.e length 1000 - 3000 characters) to an internal table.

ALSM_EXCEL_TO_INTERNAL_TABLE, only field upto 50 Characters can be uploaded.

Please , let me know if anybody has come across this situation.

Any pointers , regarding this will be highly appreciated.

Thanks in Advance,

Harika.

4 REPLIES 4

Former Member
0 Kudos

Hi

Have you tried GUI_UPLOAD.

Regards

Neha

Former Member
0 Kudos

hi

ALSM_EXCEL_TO_INTERNAL_TABLE

..yes the max field pick is 50 char in length..

Now in your case .. you cannot rely on excel upload for a field which has more than 50 char's .. since expected is >2000char length you need to save the excel contents into text file and proceed ...

so best option is you need to have a text file in this place instead of excel ..

and you have to use gui_upload to upload this text file in the currect scenario..

Br,

Vijay.

I355602
Advisor
Advisor
0 Kudos

Hi Harika Ponnam,

Enter your reocrds in an excel file and then save this file as TEXT DELIMITED file type.

This will result in a text file with your records in separate lines and columns separated by a tab.

Now, you can use GUI_UPLOAD function module to upload your file into an internal table.

Make sure that for column entries having length>50 characters, you have appropiate column length associated.

Use this code:-


REPORT ZTG_VENDRP.

TYPES : BEGIN OF VENDOR,
        LIFNR LIKE RF02K-LIFNR,
        BUKRS LIKE RF02K-BUKRS,
        EKORG LIKE RF02K-EKORG,
        KTOKK LIKE RF02K-KTOKK,
        ANRED LIKE LFA1-ANRED,
        NAME1 LIKE LFA1-NAME1,
        SORTL LIKE LFA1-SORTL,
        LAND1 LIKE LFA1-LAND1,
        SPRAS LIKE LFA1-SPRAS,
        WAERS LIKE LFM1-WAERS,
        END OF VENDOR.

DATA : VENDOR_TAB TYPE STANDARD TABLE OF VENDOR INITIAL SIZE 10 WITH HEADER LINE.

START-OF-SELECTION.

  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      FILENAME                     = 'c:\vendors.txt'
     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                      = VENDOR_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
*   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.

This will upload your records into the internal table.

Now you can use this table as per your requirements.

Hope this solves your problem.

Thanks & Regards.

Tarun Gambhir.

Former Member
0 Kudos

Hi Harika

TYPE-POOLS: truxs.

PARAMETERS: p_file TYPE  rlgrap-filename.

TYPES: BEGIN OF t_datatab,
      col1(30)    TYPE c,
      col2(30)    TYPE c,
      col3(30)    TYPE c,
      END OF t_datatab.
DATA: it_datatab type standard table of t_datatab,
      wa_datatab type t_datatab.

DATA: it_raw TYPE truxs_t_text_data.

* At selection screen
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      field_name = 'P_FILE'
    IMPORTING
      file_name  = p_file.


***********************************************************************
*START-OF-SELECTION.
START-OF-SELECTION.

  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
*     I_FIELD_SEPERATOR        =
      i_line_header            =  'X'
      i_tab_raw_data           =  it_raw         " WORK TABLE
      i_filename               =  p_file
    TABLES
      i_tab_converted_data     = it_datatab[]    "ACTUAL DATA
   EXCEPTIONS
      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.


***********************************************************************
* END-OF-SELECTION.
END-OF-SELECTION.
  LOOP AT it_datatab INTO wa_datatab.
    WRITE:/ wa_datatab-col1,
            wa_datatab-col2,
            wa_datatab-col3.
  ENDLOOP.

Regards

Surendra P