Uploading an excel file

By Deepika

For our demo purpose, we have created the following database table:

 

In our demo, we would upload an excel file from the presentation server and insert those records into the above database table.

Following is the excel file structure:

 

Program to upload the excel file:

In our program, we would use the function module “TEXT_CONVERT_XLS_TO_SAP to upload an excel file.
REPORT ZEXCEL_UPLOAD.
TYPE-POOLS truxs.
TABLES : zscarr.
* Selection screen
PARAMETER p_file TYPE rlgrap-filename DEFAULT 'C:\TEST.xls'.
TYPES:
  BEGIN OF t_tab,
    carrid TYPE zscarr-carrid,
    seats  TYPE zscarr-total_seats,
  END OF t_tab.
DATA :
  t_upload  TYPE STANDARD TABLE OF t_tab,
  wa_upload TYPE t_tab,
  it_type   TYPE truxs_t_text_data.
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 = it_type
    i_filename     = p_file
  TABLES
    i_tab_converted_data = t_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.
END-OF-SELECTION.
* Uploading the data into the database table
  LOOP AT T_UPLOAD INTO WA_UPLOAD.
    ZSCARR-CARRID = WA_UPLOAD-CARRID.
    ZSCARR-TOTAL_SEATS = WA_UPLOAD-SEATS.
    MODIFY ZSCARR.
  ENDLOOP.

Output: 

Data inserted into the table ZSCARR:

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image