cancel
Showing results for 
Search instead for 
Did you mean: 

How to upload excel file to intenal table

Former Member
0 Kudos

I am working on a webdynpro application and trying to upload excel data to internal table , i found that none of the FM are available with the system i am working on . tried with 'ALSM_EXCEL_TO_INTERNAL_TABLE' 'TEXT_CONVERT_XLS_TO_SAP'' and many others. Is There any other way to parse the excel and read it to internal table .

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

Try this code

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.

Cheers,

G.Aditya

Former Member
0 Kudos

Hi

Check the below link

http://wiki.sdn.sap.com/wiki/display/WDABAP/ExcelFileUploadAndDisplayDataUsingWebDynPro+ABAP

Former Member
0 Kudos

'HR_KR_XSTRING_TO_STRING'

this function module is not present in the dev environment i am working on

arjun_thakur
Active Contributor
0 Kudos

Hi,

Refer the following code


  data: lv_convert type REF TO CL_ABAP_CONV_IN_CE,
      lv_string type string,
      lt_string_table type table of string.
 DATA lo_el_context TYPE REF TO if_wd_context_element.
    DATA ls_context TYPE wd_this->element_context.
    DATA lv_xstring TYPE wd_this->element_context-xstring.

*   get element via lead selection
    lo_el_context = wd_context->get_element( ).

  lo_el_file_attribute->get_attribute(
    EXPORTING
      name =  `FILE_DATA`
    IMPORTING
      value = lv_xstring ).  " FILE_DATA is the name of the attribute bound to the data source property

*** Access the excel data.
lv_convert = cl_abap_conv_in_ce=>create( input = lv_xstring ).
lv_convert->read( importing data = lv_string ).   

SPLIT lv_string AT cl_abap_char_utilities=>cr_lf INTO TABLE lt_string_table.

This code has a limitation: This code works for .csv file only

I hope it helps.

Regards

Arjun