Upload Excel From Local System To SAP Table Using ABAP
Upload Excel From Local System To SAP Table Using ABAP
Categories
HOME |SAP HANA | SAP Hybris | SAP ABAP | SAP Security|SuccessFactors|S/4 HANA|SAP JOBS|SAP FREELANCE
Thursday, 22 February 2018 16:25
SAP JOBS Upload Excel from Local System to SAP Table using ABAP
[Full time] Консультант PP Written by Максим
at TeamIdea
23 hours ago font size Print Email Be the rst to comment!
[Full time] Консультант
SAP HCM at freelance Rate this item (4 votes)
4 days ago
[Full time] Консультант FI
at TeamIdea
4 days ago
ABAP Requirement: 1
Upload an excel le from local system( Ex: PC ) and insert those records into the database table using ABAP.
Step 1: Create a ZTable that is to be
De ne a structure for the internal table that holds records from the excel sheet.
https://sapbazar.com/articles/item/662-upload-excel-from-local-system-to-sap-table-using-abap 1/5
2/5/2020 Upload Excel from Local System to SAP Table using ABAP
Code:
METHOD upload_excel
.
****** FM t l d
1
2 METHOD upload_excel.
3 ****** FM to upload excel le
4 CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
5 EXPORTING
6 i_tab_raw_data = it_type
7 i_ lename = iv_ le "Filename
8 TABLES
9 i_tab_converted_data = et_upload
10 EXCEPTIONS
11 conversion_failed = 1
12 OTHERS = 2.
13 IF sy-subrc NE 0.
14 MESSAGE ID sy-msgid
15 TYPE sy-msgty
16 NUMBER sy-msgno
17 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
18 ENDIF.
19 ENDMETHOD.
20
Method FILENAME_F4_HELP
METHOD filename_f4_
help.
****** F4 h l f
1 METHOD lename_f4_help.
2 ****** F4 help for entering lename from presentation server
3 CALL FUNCTION'F4_FILENAME';
4 IMPORTING
5 le_name = ev_ lename. "Filename
6 ENDMETHOD.
Final Code:
Go to SE38,
Generate a report to update database table.
*&-- -- -- -- -
- -- -- -- -- -- --
1 *&---------------------------------------------------------------------*
2 *& Report ZEXCEL_UPLOAD
3 *&---------------------------------------------------------------------*
4 *&
5 *&---------------------------------------------------------------------*
6 REPORT zexcel_upload.
7 ****** Selection Screen
8 PARAMETERS: p_ le TYPE rlgrap- lename OBLIGATORY. "To enter le name
9 TYPES: BEGIN OF ty_str,
10 emp_id TYPE ztask-emp_id,
11 project TYPE ztask-project,
12 task TYPE ztask-task,
13 comments TYPE ztask-comments,
14 e ort TYPE ztask-e ort,
15 END OF ty_str.
16 DATA: lt_type TYPE truxs_t_text_data,
17 lt_excel TYPE TABLE OF ty_str,
18 ls_excel TYPE ty_str.
19 DATA: lt_excel_temp TYPE STANDARD TABLE OF ztask,
20 ls_excel_temp LIKE LINE OF lt_excel_temp.
21 DATA: lr_excel TYPE REF TO zcl_excel_upload.
22 ****** F4 help for fetching excel le
23 AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_ le.
24 zcl_hp_excel_upload=> lename_f4_help(
25 IMPORTING
26 ev_ lename = p_ le
27 ).
28 START-OF-SELECTION.
29 CREATE OBJECT lr_excel.
30 ****** Populating internal table using excel sheet data
31 lr_excel->upload_excel(
32 EXPORTING
33 it_type = lt_type
34 iv_ le = p_ le
35 IMPORTING
36 et_upload = lt_excel
37 ).
https://sapbazar.com/articles/item/662-upload-excel-from-local-system-to-sap-table-using-abap 2/5
2/5/2020 Upload Excel from Local System to SAP Table using ABAP
38 END-OF-SELECTION.
39 DELETE lt_excel INDEX 1. " delete header of excel sheet
40 MOVE-CORRESPONDING lt_excel TO lt_excel_temp.
41 ****** Update database table
42 IF lt_excel_temp IS NOT INITIAL.
43 MODIFY ztask FROM TABLE lt_excel_temp.
44 IF sy-subrc EQ 0.
45 **Createamessage inSE91,that the db table isupdated successfully.
46 MESSAGE i000(zhp_messages).
47 ENDIF.
48 ENDIF.
49
50
51
52
53
54
55
56
57
Result:
Максим
Leave a comment
Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.
https://sapbazar.com/articles/item/662-upload-excel-from-local-system-to-sap-table-using-abap 3/5
2/5/2020 Upload Excel from Local System to SAP Table using ABAP
Message *
enter your message here...
Name *
enter your name...
Email *
enter your e-mail address...
Website URL
enter your site URL...
Submit comment
back to top
Join to SAPBAZAR.COM
I'm a SAP Freelancer
I'm a Customer
Save tax
upto
₹46,800^
max life term insurance
Because
#YouAreTheDifference
https://sapbazar.com/articles/item/662-upload-excel-from-local-system-to-sap-table-using-abap 4/5
2/5/2020 Upload Excel from Local System to SAP Table using ABAP
https://sapbazar.com/articles/item/662-upload-excel-from-local-system-to-sap-table-using-abap 5/5