Upload excel file to an internal table

Hello,

This posting include simple abap  source code to upload excel file into an internal table.


type-pools : truxs.

*data declerations >

TYPES : BEGIN OF t_sflight ,
CARRID like sflights-CARRID,
CARRNAME like sflights-CARRNAME,
CONNID like sflights-CONNID,
COUNTRYFR like sflights-COUNTRYFR,
CITYFROM like sflights-CITYFROM,
AIRPFROM like sflights-AIRPFROM,
COUNTRYTO like sflights-COUNTRYTO,
CITYTO like sflights-CITYTO,
AIRPTO like sflights-AIRPTO,
FLDATE like sflights-FLDATE,
SEATSMAX like sflights-SEATSMAX,
SEATSOCC like sflights-SEATSOCC,
END OF t_sflight.

data : gt_upload type standard table of t_sflight,
gs_upload type t_sflight,
gt_type type truxs_t_text_data.

*selection screen >
parameter p_file type rlgrap-filename ."this is getting excel file location

*Search Help for File parameter
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
* PROGRAM_NAME = SYST-CPROG
* DYNPRO_NUMBER = SYST-DYNNR
field_name = 'P_FILE'
IMPORTING
file_name = p_file.

start-of-selection.

* uploading the data in the file into internal table
call function 'TEXT_CONVERT_XLS_TO_SAP'
exporting
* i_field_seperator =
i_line_header = 'X'
i_tab_raw_data = gt_type
i_filename = p_file
tables
i_tab_converted_data = gt_upload[]
exceptions
conversion_failed = 1
others = 2.
if sy-subrc ne 0.
message id sy-msgid
type sy-msgty
number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.

2 thoughts on “Upload excel file to an internal table

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s