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

Problem in uploading excel file

Former Member
0 Likes
2,807

HI ,

i need to upload a excel file, I am able to get records form excel to internal table, using ws_upload FM.

But i m getting a # in between every fields.

I have used split at '#' into field1 field2... but it is not working. Can anybody help me onthis.. plz..

Kumar

HI ,

i need to upload a excel file, I am able to get records form excel to internal table, using ws_upload FM.

But i m getting a # in between every fields.

I have used split at '#' into field1 field2... but it is not working. Can anybody help me onthis.. plz..

Kumar

13 REPLIES 13
Read only

Former Member
0 Likes
1,787

use GUI_UPLOAD

or

ALSM_EXCEL_TO_INTERNAL_TABLE

Funtion modules

Read only

Former Member
0 Likes
1,787

try the below code

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.

ViveK

Read only

Former Member
0 Likes
1,787

Hi,

Try using the function module "GUI_UPLOAD". Make sure you pass the interface parameter "HAS_FIELD_SEPARATOR" as #.

Manoj

Read only

0 Likes
1,787

Both upload and ws_upload does the same functionality, that is transfere data from presentation server to application server or from PC to SAP system(to an internal table).

There are very few difference between the two.

1 Upload requires a User Interaction for uploading i.e., user has to respond to the dialog boxes that appear WS_Upload does not. You just need to specify the file location in the function input parameters itself.

2 upload - u can give the file in run time wsupload - u have to give in Function module

3 upload is meant to be used by abappers. ws_upload is meant to be called by SAP. It is not a standard ABAP command.

4 ws_upload is Obsolete : No longer supported by SAP. Use <b>GUI_UPLOAD</b> instead.

Read only

0 Likes
1,787

Manoj,

if i use "HAS_FIELD_SEPARATOR" as #, i am able to get only first coloumn correctly. Other coloumns from the file are missing.

kumar

Read only

0 Likes
1,787

If i use GUI_upload,

then i m getting records like this..

"5000797#10#10.01.2006#00.00.0000#Not Found in CRM Link table for 09" . Here if i use "split lt_excel-text AT ',' into f1 f2 f3 f4 f5.", then it is not spliting.

If i use has_field_seperator = '#', then i am getting records like this, "5000797". Only first coloumn is getting properly. Others are gone.

Plz help me in this.

Kumar

Read only

0 Likes
1,787

Hi,

Does your Internal table passed to GUI_UPLOAD has all the columns specified in the Excel file. In other words, the number of columns in the internal table and Excel file should be the same.

Manoj

Read only

Former Member
0 Likes
1,787

Hi Nitin,

*..............................................................
*: Description                                                :
*: -----------                                                :
*: This is a simple example program to get data from an excel :
*: file and store it in an internal table.                    :
*:                                                            :
*:............................................................:
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.

See the below link for one more example:-

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

Regards

SUdheer

Read only

0 Likes
1,787

refer..

Read only

0 Likes
1,787

SOrry all,

i didnt mention you. I am working on CRM server. I dont have these function modules like aslm_excel_internal_table,

AND THE below example i tried, it is not working for me too..

i have got the data, but i am getting the problem in the split at '#'. it is splitting only for the first occurence and leaving the others. even i tried split for all occurences. it didnt work. my file type is ASC.

kumar

Read only

0 Likes
1,787

try this

replace all occurrences of '#' in v_str with '/'.

then use split at '/'

Read only

Former Member
0 Likes
1,787

Try using the function module "GUI_UPLOAD". Make sure you pass the interface parameter HAS_FIELD_SEPARATOR = 'X'

Read only

Former Member
0 Likes
1,787

Hi I have encountered this problem too. After trying different solutions, I guess that FM 'GUI_UPLOAD' is

not supposed to upload an excel file. So please try FM 'TEXT_CONVERT_XLS_TO_SAP' as below. It works.

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

*: 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 :

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

TYPE-POOLS: truxs.

PARAMETERS: p_file TYPE rlgrap-filename. "To retrieve the upload file name

TYPES: BEGIN OF t_datatab,

col1(10) TYPE c,

col2(10) TYPE c,

col3(10) 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 = 'X'

  • i_line_header = 'X' "To ignore the header line(the first line) if it is '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.