06-21-2007 7:55 AM
I want to get records from excel into sap system, How can I achieve that?
Code samples would be very helpful.Thanks.
Deniz.
06-21-2007 7:58 AM
Hi,
U can use Function GUI_UPLOAD to upload the data from a Notepad into an Internal table in SAP system.
But for the Excel sheet, u shud use ALSM_EXCEL_TO_INTERNAL TABLE.
Regards,
Himanshu
06-21-2007 8:04 AM
Hi,
The declaration for itab should be like this:
data: itab type standard table of ALSMEX_TABLINE.
You can use function module:
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = P_FILE
Here we have to given parameter path declared in Selection Screen
I_BEGIN_COL = 1
I_BEGIN_ROW = 1
I_END_COL = 6
Here we are giving the final number of Column
I_END_ROW = 100
Make it as Max. rows can be possible
TABLES
INTERN = IT_EXCEL
Here we have to pass Declared Internal Table for Excel
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.
WRITE 'PATH OF EXCEL FILE IS NOT CORRECT'.
EXIT.
ENDIF.
For P_FILE, Yoc can concatenate the Serial Number & '.XLS' and pass it
https://forums.sdn.sap.com/click.jspa?searchID=3321771&messageID=2161899
Regards
06-21-2007 8:11 AM
save the excel file as comma delimted file and refer below code for upload functionality -
*&---------------------------------------------------------------------*
*& Report Z_AMIT_BAPI *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT Z_AMIT_BAPI
no standard page heading line-size 255.
parameters: p_file like rlgrap-filename default 'C:tempemp.txt'.
data :begin of itab occurs 0,
pernr(8),
bdate(10),
edate(10),
mail(30) ,
end of itab.
Start-of-selection.
Perform read_file.
*&---------------------------------------------------------------------*
*& Form read_file
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM read_file .
DATA: full_file_name TYPE string.
full_file_name = p_file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = full_file_name
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = ','
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* DAT_MODE = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* CHECK_BOM = ' '
* NO_AUTH_CHECK = ' '
* IMPORTING
* FILELENGTH =
* HEADER =
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 e000(000) WITH 'Upload-Error; RC:' sy-subrc.
ENDIF.
ENDFORM. " read_file