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 data from Excel and CSV format

Former Member
0 Likes
587

hi experts,

Could anybody give me the sample code for uploading data thru BDC from Excel and CSV format.

Thanks in advance.

3 REPLIES 3
Read only

Simha_
Product and Topic Expert
Product and Topic Expert
0 Likes
542

Hi,

Use this FM ALSM_EXCEL_TO_INTERNAL_TABLE to upload excel into an internal table in call tranaction or session input.

For uploading CSV file.

First upload the csv file into internal table by using GUI_UPLOAD,

then u can concatenate the three columns

After you split the string, into its fields, just concatenate the fields into another field.

split iflat at ',' into itab-fld1 itab-fld2 itab-fld3.

concatanate itab-fld1 itab-fld2 itab-fld3 into itab-fld4 separated by '-'.

append itab.

Cheers,

Simha.

Read only

Former Member
0 Likes
542

DATA: BEGIN OF i_file_data OCCURS 0,

col1 TYPE text60,

col2 TYPE text60,

col3 TYPE text60,

col4 TYPE text60,

col5 TYPE text60,

col6 TYPE text60,

END OF i_file_data.

parameter: p_local TYPE rlgrap-filename MODIF ID m2.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_local.

*F4 help to browse file in local server

PERFORM select_local_file.

Start-of-selection.

    • Get file extension

SPLIT p_local AT '.' INTO lv_file

lv_ext.

TRANSLATE lv_ext TO UPPER CASE.

CLEAR i_file_data.

REFRESH i_file_data.

IF lv_ext = c_xls.

      • IF file is excel get data from excel sheet

PERFORM get_xls_file.

ELSE.

    • Else get file from gui download

PERFORM get_txt_file.

ENDIF. "lv_ext

FORM get_xls_file.

data: i_raw TYPE truxs_t_text_data.

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'

EXPORTING

i_field_seperator = 'X'

i_tab_raw_data = i_raw

i_filename = p_local

TABLES

i_tab_converted_data = i_file_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. " sy-subrc

ENDFORM. "get_xls_file

FORM get_txt_file.

DATA: lv_string TYPE string. " To get file path

CLEAR lv_string.

lv_string = p_local. " Get file path

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = lv_string

filetype = 'ASC'

has_field_separator = 'X'

read_by_line = 'X'

TABLES

data_tab = i_file_data[]

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. " sy-subrc

ENDFORM. "get_txt_file

FORM select_local_file.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

program_name = sy-cprog

dynpro_number = sy-dynnr

field_name = space

IMPORTING

file_name = p_local.

ENDFORM. "select_local_file

*****Now i_file_data contains the field values. You can move to your internal table which is declared according to the actual data types. For this, you need to loop thru i_file_data and move specific column values to the internal table.

Edited by: Eswara Rao Aakula on Dec 24, 2007 7:35 AM

Read only

Former Member
0 Likes
542

This message was moderated.