0% found this document useful (0 votes)
31 views

Excel To Internal Table Using Classess

Uploaded by

Jagath Jayasurya
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Excel To Internal Table Using Classess

Uploaded by

Jagath Jayasurya
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

types: BEGIN OF ty_final1,

pspid TYPE string, "zps_assessment-pspid,


docid TYPE string,
v_type TYPE string,
udid TYPE string,
legacy TYPE string,
dis_benefcode TYPE string,
END OF ty_final1,

PARAMETERS p_file TYPE ibipparms-path OBLIGATORY.

TYPES: BEGIN OF xls_line,


data(256) TYPE x,
END OF xls_line.

DATA : lt_bin_data TYPE STANDARD TABLE OF xls_line,


it_string TYPE TABLE OF ty_final1,
lv_file TYPE string.

lv_file = p_file.

cl_gui_frontend_services=>gui_upload(
EXPORTING
filename = lv_file
filetype = 'BIN'
IMPORTING
filelength = DATA(lv_file_length)
header = DATA(lv_xstring_header)
CHANGING
data_tab = lt_bin_data
EXCEPTIONS
OTHERS = 99 ).

cl_progress_indicator=>progress_indicate(
EXPORTING
i_text = 'Loading the excel data....'
i_processed = 50
i_total = 100
i_output_immediately = abap_true ).

"CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'


CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
input_length = lv_file_length
IMPORTING
buffer = lv_xstring_header
TABLES
binary_tab = lt_bin_data
EXCEPTIONS
failed = 1
OTHERS = 2.
IF sy-subrc = 0.

TRY.
DATA(lo_excel) = NEW cl_fdt_xl_spreadsheet(
document_name = lv_file
xdocument = lv_xstring_header ) .
lo_excel->if_fdt_doc_spreadsheet~get_worksheet_names(
IMPORTING
worksheet_names = DATA(lt_worksheets) ).

DATA(lv_woksheetname) = lt_worksheets[ 1 ]. "Read first sheet


DATA(lo_data_ref) = lo_excel-
>if_fdt_doc_spreadsheet~get_itab_from_worksheet(
lv_woksheetname ).

ASSIGN lo_data_ref->* TO FIELD-SYMBOL(<lfs_data_tab>).


**** cl_demo_output=>display( <lfs_data_tab> ).
IF <lfs_data_tab> IS ASSIGNED.
it_string[] = <lfs_data_tab>.
ENDIF.

CATCH cx_fdt_excel_core.
"Error handling
ENDTRY.

ENDIF.

IF it_string IS INITIAL.
MESSAGE 'Error Uploading file' TYPE 'S' DISPLAY LIKE 'E'.
ELSE.
REFRESH : it_final.
DELETE it_string INDEX 1.
MOVE-CORRESPONDING IT_STRING TO IT_FINAL.
ENDIF.

You might also like