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: 

how to upload an excel file into SAP

Former Member
0 Kudos

hi,

i have to upload an excel file in SAP,

ive used the function module WS_UPLOAD but I dont know which filetype to use:BINARY, ASC etc.

Ca anybody help me?

Regards

Anjali

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Sia,

I we can use FM 'ALSM_EXCEL_TO_INTERNAL_TABLE' to do this. below is the example code.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

filename = p_file

i_begin_col = '1'

i_begin_row = '1' "Do not require headings

i_end_col = '10'

i_end_row = '10000'

TABLES

intern = itab

EXCEPTIONS

inconsistent_parameters = 1

upload_ole = 2

OTHERS = 3.

IF sy-subrc <> 0.

MESSAGE e001(zz) WITH text-005.

"Problem uploading Excel Spreadsheet

ENDIF.

Regrads

Srikanth M

12 REPLIES 12

andreas_mann3
Active Contributor
0 Kudos

hi,

better save your data as csv-file in excel

and use fm gui_download

A.

Message was edited by: Andreas Mann

Former Member
0 Kudos

if you want to upload data from a XLS file, then proceed as given in the link.

use the FM : TEXT_CONVERT_XLS_TO_SAP.

check this link

http://www.sapdevelopment.co.uk/file/file_upexcel.htm

here is the small piece of code(copied from one of the SDN post)

REPORT  zupload_excel_to_itab.

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.

alternatively you also can check,

Regards,

Srikanth

Message was edited by: Srikanth Kidambi

Message was edited by: Srikanth Kidambi

Former Member
0 Kudos

Use FM GUI_UPLOAD, save the file in tab delimited format and use the FM.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = lcl_filename

filetype = 'ASC'

has_field_separator = 'X'

TABLES

data_tab = i_input

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.

Regards,

Prakash.

anversha_s
Active Contributor
0 Kudos

hi,

chk this extract

*..............................................................

*: Description :

*: -


:

*: This is a simple example program to get data from an excel :

*: file and store it in an internal table. :

*: :

*: Author : www.sapdev.co.uk, based on code from Jayanta :

*: :

*: SAP Version : 4.7 :

*:............................................................:

REPORT zupload_excel_to_itab.

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.

rgds

anver

Former Member
0 Kudos

remmber , in background gui_upload/download not work

DATA:ITAB_CSV(40) TYPE C OCCURS 0 WITH HEADER LINE.

IF P_SERVR = 'X'. " Input file on server

OPEN DATASET FILE FOR INPUT MESSAGE MSG

IN TEXT MODE ENCODING DEFAULT .

  • OPEN DATASET file IN LEGACY TEXT MODE CODE PAGE '9999' FOR INPUT.

" in binary mode.

IF SY-SUBRC = 0.

DO.

READ DATASET FILE INTO ITAB_CSV1 .

IF SY-SUBRC <> 0.

WA_SUBRC = SY-SUBRC.

IF WA_SUBRC = 4.

WA_SUBRC = 0.

ENDIF.

EXIT.

ELSE.

DATA: C_TAB TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.

C_TAB = ',' .

SPLIT ITAB_CSV1 AT C_TAB INTO

IT_BKPF-AWKEY

IT_BKPF-BUZEI

IT_BKPF-LIFNR

IT_BKPF-XREF_NEW.

APPEND IT_BKPF.

ENDIF.

ENDDO.

ENDIF.

ELSE. " Input file on local disk

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

FILENAME = FILE

  • filetype = 'ASC'

TABLES

DATA_TAB = ITAB_CSV

EXCEPTIONS

CONVERSION_ERROR = 1

FILE_OPEN_ERROR = 2

FILE_READ_ERROR = 3

INVALID_TYPE = 4

NO_BATCH = 5

UNKNOWN_ERROR = 6

INVALID_TABLE_WIDTH = 7

GUI_REFUSE_FILETRANSFER = 8

CUSTOMER_ERROR = 9

OTHERS = 10.

WA_SUBRC = SY-SUBRC.

IF WA_SUBRC <> 0.

WRITE:/ 'Error in loading file',SY-SUBRC.

STOP.

ENDIF.

LOOP AT ITAB_CSV.

SPLIT ITAB_CSV AT ',' INTO

IT_BKPF1-AWKEY

IT_BKPF1-BUZEI

IT_BKPF1-LIFNR

IT_BKPF1-XREF_NEW.

APPEND IT_BKPF1.

ENDLOOP.

Former Member
0 Kudos

Hey its

GUI_UPLOAD u have to use....chk this

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = 'C:\XYZ.txt' <u><i><b>(**can be your fie of ur format**)</b></i></u>

filetype = 'ASC'

has_field_separator = 'X'

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.

thanks

SONY

Former Member
0 Kudos

Hi Sia,

I we can use FM 'ALSM_EXCEL_TO_INTERNAL_TABLE' to do this. below is the example code.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

filename = p_file

i_begin_col = '1'

i_begin_row = '1' "Do not require headings

i_end_col = '10'

i_end_row = '10000'

TABLES

intern = itab

EXCEPTIONS

inconsistent_parameters = 1

upload_ole = 2

OTHERS = 3.

IF sy-subrc <> 0.

MESSAGE e001(zz) WITH text-005.

"Problem uploading Excel Spreadsheet

ENDIF.

Regrads

Srikanth M

Former Member
0 Kudos

Hi sia,

Go to se37 enter that function module "WS_UPLOAD"

At the to right side there is a check button FUNCTION MODULE DOCUMENTATION just click on that you can see the documentation of that FM.

Thanks

Vikranth Khimavath

Former Member
0 Kudos

Ive used the fm TEXT_CONVERT_XLS_TO_SAP

Thanks Srikanth!

0 Kudos

if your problem is solved, close the post.

Thanks

Srikanth.

0 Kudos

Hi,

I have en excel sheet where header is on row 1 and data is from row2 .

How do i upload only the data from row 2 using this FM TEXT_CONVERT_XLS_TO_SAP

Plz help me...

Also, I want to validate the data in column1 ( If the data in col1 is not equal to a,z) then i need to create a error file

Former Member
0 Kudos

Thanks folks. This was really useful.

- Birla.