Excel Upload Using RAP Application

Hello Experts,

We are currently facing an issue with the file upload requirement using RAP model where the business needs to upload .XLS/.XLSX file from a custom RAP application. At the moment, we have successfully built the custom RAP app, which allows the upload of .CSV files, and we are able to process and alter the data as required. However, we are struggling to find a solution for uploading .XLS/.XLSX files.

Although we receive the data in RAWSTRING format using the Read Entity statement, we are unable to convert the RAWSTRING to our internal table. We are using the cl_abap_conv_codepage=>create_in()->convert method, but the system throws a dump at line: ‘SYSTEM-CALL CONVERT ID 44’ when attempting to call the convert method for .XLS/.XLSX files.

I have gone through multiple blogs shared on SAP Communities, but most solutions focus on uploading .CSV files. Could anyone provide guidance on this issue? We have several custom app development requirements, and this functionality will serve as a base for all of our file upload processes. Any priority support on this matter would be greatly appreciated!

For reference, I am pasting my uploadExcel method code below:

METHOD uploadexceldata.

READ ENTITIES OF zc_head_upd IN LOCAL MODE

ENTITY zc_head_upd

ALL FIELDS WITH

CORRESPONDING #( keys )

RESULT DATA(lt_inv).

 

** Get attachment value from the instance

DATA(lv_attachment) = lt_inv[ 1 ]-attachment.

 

** Data declarations

TYPES: BEGIN OF ty_excel_data,

mandt TYPE mandt,

svono TYPE aufnr,

startday TYPE char10,

zgroup TYPE char10,

area TYPE char10,

revtx TYPE revtx,

duration TYPE char2,

shift TYPE char2,

pitchid TYPE char50,

startpitch TYPE char4,

seq TYPE char2,

id TYPE char50,

lastchangedat TYPE abp_lastchange_tstmpl,

END OF ty_excel_data.

 

DATA: rows TYPE STANDARD TABLE OF string,

content TYPE string,

conv TYPE REF TO cl_abap_conv_codepage,

ls_excel_data TYPE ty_excel_data,

lt_excel_data TYPE STANDARD TABLE OF ty_excel_data, “zps_dataupd_itm,

lt_excel_data_final TYPE TABLE OF zps_dataupd_itm,

lv_date TYPE char40,

lv_svono TYPE aufnr,

lv_timestamp TYPE timestampl.

 

DATA: lt_table TYPE TABLE OF standard.

 

GET TIME STAMP FIELD lv_timestamp.

lv_date = lv_timestamp.

 

content = cl_abap_conv_codepage=>create_in( )->convert( lv_attachment ).

 

** Split the string table to rows

SPLIT content AT cl_abap_char_utilities=>cr_lf INTO TABLE rows.

 

** Process the rows and append to the internal table

LOOP AT rows INTO DATA(ls_row) FROM 2.

SPLIT ls_row AT ‘,’ INTO ls_excel_datarevtx

ls_excel_datazgroup

ls_excel_datasvono

ls_excel_dataarea

ls_excel_datastartday

ls_excel_dataduration

ls_excel_datashift

ls_excel_datapitchid

ls_excel_datastartpitch

ls_excel_dataseq

ls_excel_dataid.

 

ls_excel_datalastchangedat = lv_date.

 

APPEND ls_excel_data TO lt_excel_data.

 

* LOOP AT lt_excel_data ASSIGNING FIELD-SYMBOL(<fs>).

* <fs>-last_changed_at = lv_date.

* ENDLOOP.

 

 

CLEAR: ls_row, ls_excel_data.

 

LOOP AT lt_excel_data ASSIGNING FIELD-SYMBOL(<fs_excel_data>).

APPEND INITIAL LINE TO lt_excel_data_final ASSIGNING FIELD-SYMBOL(<fs_excel_final>).

MOVE-CORRESPONDING <fs_excel_data> TO <fs_excel_final>.

ENDLOOP.

 

MODIFY zps_dataupd_itm FROM TABLE lt_excel_data_final.

CLEAR: lt_excel_data, lt_excel_data_final.

ENDLOOP.

 

ENDMETHOD.

Best Regards

Scroll to Top