cancel
Showing results for 
Search instead for 
Did you mean: 

Development Objects are not permitted in ABAP Environment(BTP) | Excel Upload and Processing of Data

Fabio7
Explorer

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

Sandra_Rossi
Active Contributor
0 Kudos
XCO_CP_XLSX? Also, volunteers to adapt abap2xlsx to the Cloud are welcome.

Accepted Solutions (1)

Accepted Solutions (1)

k_vadym
Advisor
Advisor

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.

Fabio7
Explorer
0 Kudos
Hi k_vadym, thank you very much for your support! 🙂 Now it works for me! Note: iv_name must correspond to the name of the Excel worksheet so that the corresponding object can be instantiated without errors.

Answers (1)

Answers (1)

amitdiwane
Advisor
Advisor
0 Kudos

Hello Fabio,

You can refer this blog series and try this approach: https://community.sap.com/t5/technology-blogs-by-members/excel-upload-using-rap-part-3/ba-p/13523443