You are on page 1of 5

2/5/2020 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

updated through excel.


Step 2: Excel Structure that is to be uploaded.
Step 3: Program to upload excel. (With explanation)
There are many function modules in SAP ABAP to upload an excel le from presentation  server to database. Using FM –
TEXT_CONVERT_XLS_TO_SAP & Go to SE24 to create a global class which will have methods to Upload Excel and F4 help for le name.

De ne a structure for the internal table that holds records from the excel sheet.

Method UPLOAD_EXCEL with below parameters

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:

Provide excel lename using F4 help as shown below.

On F8, Excel records will be uploaded to the DB table.


Table entries : ZTASK

Read 14595 times

Tweet Like 0 Share

Published in SAP ABAP

Максим

Latest from Максим

SAP Analytics Cloud Add-in for MS O ce (beta) – First Look


SAP CodeJam goes Herne
ESS – 2020 W-4 Filing Status FIX
ESS – 2020 W-4 Filing Status Drop-Down FIX
BUS Screen Framework – Working with Tabstrips

More in this category: « SAP ABAP Latest Blogs SAP reading »

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

I'm not a robot


reCAPTCHA
Privacy - Terms

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

^As per prevailing tax laws I *Disclaimer I


ARN: 070120/MFY/TAX-1

'; jQuery('body').append(panel); setTimeout(showPanel, 1200); function showPanel() { jQuery('#easycookieinfo').slideDown('slow'); } jQuery('.accept a').on('click',


function() { var exp_date = new Date(); exp_date.setTime(exp_date.getTime() + (1000*3600*24*365)); document.cookie =
'cookie_32af4b2b4053a2018154d37f74abb95f=accepted;expires='+exp_date.toUTCString()+';path=/'; jQuery('#easycookieinfo').slideUp('slow'); return false; }); });

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

EasyCookieInfo Useful Links


About Us
Accepted Terms & Conditions
Disclaimer
Support
Contact Us
Follow us on
    

https://sapbazar.com/articles/item/662-upload-excel-from-local-system-to-sap-table-using-abap 5/5

You might also like