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

uploading the excel files

Former Member
0 Likes
1,387

Hey guys,

I have an excel file with some data in the form on table in it. I want to upload it into the program and transfer the content into an internal table. Any ways to do this?

Thanks in advance.

1 ACCEPTED SOLUTION
Read only

I355602
Product and Topic Expert
Product and Topic Expert
0 Likes
1,364

Hi Harshad Mishrikotkar,

To upload a flat file into an internal table.

First enter the records in an excel file and then save it as TEXT DELIMITED file type.

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

Now use this file to upload records into internal table.

Use this sample code, its working.


REPORT Z_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.

Hope this solves your problem.

Thanks & Regards.

Tarun Gambhir.

9 REPLIES 9
Read only

Former Member
0 Likes
1,364

Hi..

Use GUI_UPLOAD function module...

CHeers...

Read only

Former Member
0 Likes
1,364

Hi,

use function:

PARAMETERS: pa_data1 TYPE rlgrap-filename

DEFAULT 'C:\Migration\lieferanten.txt',

CALL FUNCTION 'WS_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE = ' '

  • CODEPAGE = ' '

filename = pa_data1

filetype = 'DAT'

  • MODE = ' '

  • WK1_N_FORMAT = ' '

  • WK1_N_SIZE = ' '

  • WK1_T_FORMAT = ' '

  • WK1_T_SIZE = ' '

  • COL_SELECT = ' '

  • COL_SELECTMASK = ' '

  • NO_AUTH_CHECK = ' '

  • IMPORTING

  • FILELENGTH =

TABLES

data_tab = itab

  • FIELDNAMES =

EXCEPTIONS

file_open_error = 1

file_write_error = 2

invalid_filesize = 3

invalid_type = 4

no_batch = 5

unknown_error = 6

invalid_table_width = 7

gui_refuse_filetransfer = 8

customer_error = 9

OTHERS = 10

.

Read only

Former Member
0 Likes
1,364

Hi,

Try this code

 DATA l_count TYPE sy-tabix.

   CONSTANTS: lc_begin_col TYPE i VALUE '1',

              lc_begin_row TYPE i VALUE '2',

              lc_end_col   TYPE i VALUE '2',

              lc_end_row   TYPE i VALUE '3000'.

* Begin of CALK912848 - Carlos Werberich - 16Sep08

  CLEAR p_i_excel_data. REFRESH p_i_excel_data.

* End   of CALK912848 - Carlos Werberich - 16Sep08

* Function module to read excel file and convert it into internal table

   CALL FUNCTION 'KCD_EXCEL_OLE_TO_INT_CONVERT'

     EXPORTING

       filename                = p_p_file

       i_begin_col             = lc_begin_col

       i_begin_row             = lc_begin_row

       i_end_col               = lc_end_col

       i_end_row               = lc_end_row

     TABLES

       intern                  = i_data

     EXCEPTIONS

       inconsistent_parameters = 1

       upload_ole              = 2

       OTHERS                  = 3.

* Error in file upload

   IF sy-subrc NE 0 .

     MESSAGE text-006 TYPE 'E'.

     EXIT.

   ENDIF.

   IF i_data[] IS INITIAL .

     MESSAGE text-007 TYPE 'E'.

     EXIT.

   ELSE.

     SORT i_data BY row col .

* Loop to fill data in Internal Table

     LOOP AT i_data .

       MOVE i_data-col TO l_count .

       ASSIGN COMPONENT l_count OF STRUCTURE p_i_excel_data TO  .

       AT END OF row .

* Append data into internal table

         APPEND p_i_excel_data.

         CLEAR p_i_excel_data.

       ENDAT .

     ENDLOOP .

   ENDIF 

Read only

I355602
Product and Topic Expert
Product and Topic Expert
0 Likes
1,365

Hi Harshad Mishrikotkar,

To upload a flat file into an internal table.

First enter the records in an excel file and then save it as TEXT DELIMITED file type.

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

Now use this file to upload records into internal table.

Use this sample code, its working.


REPORT Z_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.

Hope this solves your problem.

Thanks & Regards.

Tarun Gambhir.

Read only

Former Member
0 Likes
1,364

Hi,

Use the below function module.

DATA: l_file TYPE rlgrap-filename,

l_truxs TYPE truxs_t_text_data.

DATA : g_t_excel TYPE g_ty_excel OCCURS 0 WITH HEADER LINE.

START-OF-SELECTION.

*Converting Excel to SAP

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'

EXPORTING

i_tab_raw_data = l_truxs

i_filename = l_file

TABLES

i_tab_converted_data = g_t_excel.

IF sy-subrc <> 0.

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

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

ENDIF.

g_t_excel will be the internal table into which your data will be loaded into from ur PC Excel file.

Regards,

Uma

Read only

Former Member
0 Likes
1,364

Hi,

Try with this FM

TEXT_CONVERT_XLS_TO_SAP

ALSM_EXCEL_TO_INTERNAL_TABLE

Regards,

Suresh

Read only

Former Member
0 Likes
1,364

Hi,

Its working, implement as per ur req:


   START-OF-SELECTION.


CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
  EXPORTING
*   I_FIELD_SEPERATOR          =
*   I_LINE_HEADER              = u2018Xu2019
    I_TAB_RAW_DATA             = it_raw
    I_FILENAME                 = 'C:\PRI.XLS'
  TABLES
    I_TAB_CONVERTED_DATA       = it_datatab[]
* 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.

Thanks & Regards,

Krishna..

Read only

Former Member
0 Likes
1,364

Hi,

Try the code:

-



DATA itab TYPE TABLE OF alsmex_tabline WITH HEADER LINE.

START-OF-SELECTION.
  *progname = sy-repid.*
*read upload excel doc.*
  CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
       EXPORTING
            filename                = p_file "upload file's path
            i_begin_col             = 1
            i_begin_row             = 1
            i_end_col               = 200
            i_end_row               = 10000
       TABLES
            intern                  = itab
       EXCEPTIONS
            inconsistent_parameters = 1
            upload_ole              = 2
            OTHERS                  = 3.
  IF sy-subrc  0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

-


Best Regards,

Wind lin

Edited by: wind lin on Dec 8, 2008 10:17 AM

Read only

Former Member
0 Likes
1,364

Hi,

Try the code:

-



DATA itab TYPE TABLE OF alsmex_tabline WITH HEADER LINE.

START-OF-SELECTION.
  *progname = sy-repid.*
*read upload excel doc.*
  CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
       EXPORTING
            filename                = p_file "upload file's path
            i_begin_col             = 1
            i_begin_row             = 1
            i_end_col               = 200
            i_end_row               = 10000
       TABLES
            intern                  = itab
       EXCEPTIONS
            inconsistent_parameters = 1
            upload_ole              = 2
            OTHERS                  = 3.
  IF sy-subrc  0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

-


Best Regards,

Wind lin