2024 Mar 12 2:41 PM - edited 2024 Mar 12 2:42 PM
Use case:
I use the RAP model to build an app on the BTP in which I can upload an Excel file. The upload saves the Excel in hexadecimal format in a table.
The aim is now to convert the data into a "readable" form. Then the data should be saved in an internal table for further processing in the backend.
I can already manage the conversion on the on-premise system. Below you will find the coding of how I get from the raw string (hexadecimal format of Excel) to my internal table.
TYPES : BEGIN OF gty_uploadFile,
col1 TYPE String,
col2 TYPE String,
col3 TYPE String,
END OF gty_uploadFile.
TYPES gty_uploadFile_tt TYPE STANDARD TABLE OF gty_uploadFile.
TYPES : BEGIN OF gty_uploadFileStructured,
col1 TYPE vkorg,
col2 TYPE matnr,
col3 TYPE char250,
END OF gty_uploadFileStructured.
TYPES gty_uploadFileStructured_tt TYPE STANDARD TABLE OF gty_uploadfilestructured.
DATA gt_uploadFileStructured TYPE gty_uploadFileStructured_tt.
SELECT SINGLE FROM table_excel
FIELDS attachment
WHERE document_id = 1
INTO (iv_exceldata). "hexadecimal format of excel
DATA(lt_binary_data) = CL_BCS_CONVERT=>XSTRING_TO_SOLIX(
EXPORTING
iv_xstring = iv_exceldata
).
DATA(go_spreadsheet) = NEW cl_fdt_xl_spreadsheet(
document_name = CONV #( 'testname' )
xdocument = cl_bcs_convert=>solix_to_xstring( it_solix = lt_binary_data )
).
go_spreadsheet->if_fdt_doc_spreadsheet~get_worksheet_names(
IMPORTING worksheet_names = DATA(gt_worksheetNames)
).
IF lines( gt_worksheetNames ) > 0.
DATA(go_worksheet_itab) = go_spreadsheet->if_fdt_doc_spreadsheet~get_itab_from_worksheet(
worksheet_name = gt_worksheetNames[ 1 ] ).
FIELD-SYMBOLS <gt_worksheet> TYPE gty_uploadFile_tt.
ASSIGN go_worksheet_itab->* TO <gt_worksheet>.
LOOP AT <gt_worksheet> ASSIGNING FIELD-SYMBOL(<gs_worksheet_line>).
IF sy-tabix = 1.
CONTINUE.
ENDIF.
APPEND VALUE gty_uploadfilestructured(
col1 = <gs_worksheet_line>-col1
col2 = |{ <gs_worksheet_line>-col2 ALPHA = IN }|
col3 = <gs_worksheet_line>-col3 )
TO gt_uploadFileStructured.
ENDLOOP.
out->write( gt_uploadfilestructured ).
ENDIF.
But now to my problem. I cannot use some of the objects on the BTP because I get the following error messages:
- The use of Class CL_BCS_CONVERT is not permitted.
- The use of Class CL_FDT_XL_SPREADSHEET is not permitted.
- The use of Interface IF_FDT_DOC_SPREADSHEET is not permitted.
I can see why this is the case and that these classes are not suitable for the cloud. However, after extensive research, I could not find an alternative that works on the cloud.
So my question is: Is there an alternative for these classes and the interface that works for the BTP?
I look forward to your support!
Best regards,
Fabio
Hello, you can use class xco_cp_xlsx to convert excel-string into internal table in cloud development. Try this code:
DATA(lo_xlsx) = xco_cp_xlsx=>document->for_file_content( iv_file_content = iv_xstring )->read_access( ).
DATA(lo_worksheet) = lo_xlsx->get_workbook( )->worksheet->for_name( iv_name = 'Sheet1' ).
DATA(lo_selection_pattern) = xco_cp_xlsx_selection=>pattern_builder->simple_from_to( )->get_pattern( ).
lo_worksheet->select( lo_selection_pattern
)->row_stream(
)->operation->write_to( REF #( rt_records )
)->if_xco_xlsx_ra_operation~execute( ).
Where iv_xstring is an excel file converted into string and rt_records is a DDIC-table type which represents structure of your excel table.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
57 | |
10 | |
7 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.