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

excel file-BDC

Former Member
0 Likes
753

guyz! wat do we need ta do to convert a non-SAP system EXCEL file into SAP???? using BDC concept...

we allwayz use .TXT file as flat file.......but wat if we use excel file...how can we do using excel file???

guyz! wat do we need ta do to convert a non-SAP system EXCEL file into SAP???? using BDC concept...

we allwayz use .TXT file as flat file.......but wat if we use excel file...how can we do using excel file???

5 REPLIES 5
Read only

Former Member
0 Likes
700

use <b> gui_upload</b> to upload ur excel sheet to internal table.

Read only

Former Member
0 Likes
700

can't we use UPLOAD and do so...???

Read only

Former Member
0 Likes
700

Hi Zidene,

chk this

TYPES :ITAB TYPE ALSMEX_TABLINE.
DATA: ITAB TYPE STANDARD TABLE OF ITAB WITH HEADER LINE.


Data:filename type rlgrap-filename .
filename = 'D:Documents and Settings501030562DesktopBook1.xls'.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = filename
i_begin_col = 1
i_begin_row = 1
i_end_col = 1
i_end_row = 1
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.

Read only

aris_hidalgo
Contributor
0 Likes
700

Hi Ziden,

You can use the following FM's:

1. 'ALSM_EXCEL_TO_INTERNAL_TABLE'

2. GUI_UPLOAD

  • Checvk the said FMs in SE37 to know more about it. You can also test it from there.

Below are the details of the said FMs:

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename =

  • FILETYPE = 'ASC'

  • HAS_FIELD_SEPARATOR = ' '

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • IMPORTING

  • FILELENGTH =

  • HEADER =

tables

data_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.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

filename =

i_begin_col =

i_begin_row =

i_end_col =

i_end_row =

tables

intern =

  • 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.

Hope this helps...

P.S. Please award points for useful answers.

Read only

Former Member
0 Likes
700

hi, sample code is ::

DATA : BEGIN OF TYP_INPUT ,

MATNR LIKE MARA-MATNR,

WERKS LIKE MARC-WERKS,

LGORT LIKE MARD-LGORT,

LGNUM LIKE MLGN-LGNUM,

LGTYP LIKE MLGT-LGTYP,

LTKZA LIKE MLGN-LTKZA,

LTKZE LIKE MLGN-LTKZE,

LGBKZ LIKE MLGN-LGBKZ,

LGPLA LIKE MLGT-LGPLA,

END OF TYP_INPUT.

*Input File Data

DATA : IT_FILE LIKE TYP_INPUT OCCURS 0 WITH HEADER LINE.

*"INTERNAL TAB TO TAKE EXCEL SHEET.

DATA : IT_EXCEL LIKE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.

CALL FUNCTION <b>'ALSM_EXCEL_TO_INTERNAL_TABLE'</b>

EXPORTING

FILENAME = P_PFILE

I_BEGIN_COL = 1

I_BEGIN_ROW = 2

I_END_COL = 9

I_END_ROW = 6000

TABLES

INTERN = IT_EXCEL

EXCEPTIONS

INCONSISTENT_PARAMETERS = 1

UPLOAD_OLE = 2

OTHERS = 3.

  • If Error Opening File

IF SY-SUBRC NE 0.

  • Message : Unable to Open File

MESSAGE I102.

STOP.

ENDIF.

****************************************************************

  • IT_EXCEL CONTAINS DATA IN THE FORM OF ROW, COL, VALUE *

  • CONVERTING THAT INTERNAL TABLE TO FORMAT THAT OF EXCEL SHEET *

****************************************************************

IF NOT IT_EXCEL[] IS INITIAL.

SORT IT_EXCEL BY ROW COL.

LOOP AT IT_EXCEL.

CASE IT_EXCEL-COL.

WHEN 1.

IT_FILE-MATNR = IT_EXCEL-VALUE.

WHEN 2.

IT_FILE-WERKS = IT_EXCEL-VALUE.

WHEN 3.

IT_FILE-LGORT = IT_EXCEL-VALUE.

WHEN 4.

IT_FILE-LGNUM = IT_EXCEL-VALUE.

WHEN 5.

IT_FILE-LGTYP = IT_EXCEL-VALUE.

WHEN 6.

IT_FILE-LTKZA = IT_EXCEL-VALUE.

WHEN 7.

IT_FILE-LTKZE = IT_EXCEL-VALUE.

WHEN 8.

IT_FILE-LGBKZ = IT_EXCEL-VALUE.

WHEN 9.

IT_FILE-LGPLA = IT_EXCEL-VALUE.

ENDCASE.

AT END OF ROW.

APPEND IT_FILE.

CLEAR IT_FILE.

ENDAT.

ENDLOOP.

ELSE.

MESSAGE I000 WITH 'The input file is empty'.

STOP.

ENDIF.

Regards

Ashok P.