How to upload normal excell file to ztable

Hi All there,
Can anybody tell me how to upload normal excell file to ztable directly.
pl provide detail coding
Regards
Sagar

Hi Sagar,
   first upload the excel data into your internal table using a FM than upload the data to your ZTABLE using BDC.
parameters:
  p_file type rlgrap-filename          " File name
  data:
    lw_file  type string.              " File Path
data:
  t_bdcdata type
   standard table
         of bdcdata,
  fs_bdcdata type bdcdata.             " Work area for bdcdata
* Messages of call transaction
data:
  t_messtab type
   standard table
         of bdcmsgcoll,
  fs_messtab type bdcmsgcoll.          " Work area for messtab
at selection-screen on value-request for p_file.
  call function 'F4_FILENAME'
   exporting
     program_name        = syst-cprog
     dynpro_number       = syst-dynnr
     field_name          = ' '
   importing
     file_name           = p_file.
  lw_file = p_file.
  call function 'GUI_UPLOAD'
    exporting
      filename                    = lw_file
      filetype                    = 'ASC'
      has_field_separator         = 'X'
      dat_mode                    = 'X'
    tables
      data_tab                    = t_final_data
    exceptions
      file_open_error              = 1
      file_read_error              = 2
      no_batch                     = 3
      gui_refuse_filetransfer      = 4
      invalid_type                 = 5
      no_authority                 = 6
      unknown_error                = 7
      bad_data_format              = 8
      header_not_allowed           = 9
      separator_not_allowed        = 10
      header_too_long              = 11
      unknown_dp_error             = 12
      access_denied                = 13
      dp_out_of_memory             = 14
      disk_full                    = 15
      dp_timeout                   = 16
      others                       = 17.
  if sy-subrc <> 0.
    message id sy-msgid type sy-msgty number sy-msgno
          with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.                               " IF SY-SUBRC <> 0
  if t_final_data is initial.
    message 'File not found'(003) type 'E'.
  endif.                               " IF T_FINAL_DATA IS INITIAL
end-of-selection.
  perform upload_0585_data_using_bdc.  " populate the bdcdata table using tcode SHDB
  call transaction 'PA30' using t_bdcdata
                           mode 'A'
                       messages into t_messtab.
form upload_0585_data_using_bdc.
  loop at t_final_data into fs_final_data.
perform bdc_field       using 'Q0585-ACNTR(07)'
                               w_curr.
perform bdc_field       using 'Q0585-ACOPC'
                               lw_flag.
perform bdc_field       using 'BDC_OKCODE'
                              '=UPD'.
perform bdc_dynpro      using 'MP058500' '2000'.
perform bdc_field       using 'BDC_OKCODE'
                              '/EBCK'.
perform bdc_dynpro      using 'SAPMP50A' '1000'.
endloop.
*        Start new screen                                              *
form bdc_dynpro using program dynpro.
  clear fs_bdcdata.
  fs_bdcdata-program  = program.
  fs_bdcdata-dynpro   = dynpro.
  fs_bdcdata-dynbegin = 'X'.
  append fs_bdcdata to t_bdcdata.
endform.                               " Form bdc_dynpro using program...
*        Insert field                                                  *
form bdc_field using fnam fval.
    clear fs_bdcdata.
    fs_bdcdata-fnam = fnam.
    fs_bdcdata-fval = fval.
    append fs_bdcdata to t_bdcdata.
endform.                               " Form bdc_field using fnam fval
With luck,
Pritam.

Similar Messages

  • How to upload an excel file using ABAP.

    Hi,
    Can anyone please help me in understanding how to upload an excel file using ABAP.
    Thanks!!

    http://diocio.wordpress.com/2007/02/12/sap-upload-excel-document-into-internal-table/
    check the link
    TYPES: Begin of t_record,
    name1 like itab-value,
    name2 like itab-value,
    age   like itab-value,
    End of t_record.
    DATA: it_record type standard table of t_record initial size 0,
    wa_record type t_record.
    DATA: gd_currentrow type i.
    *Selection Screen Declaration
    PARAMETER p_infile like rlgrap-filename.
    *START OF SELECTION
    call function ‘ALSM_EXCEL_TO_INTERNAL_TABLE’
    exporting
    filename                = p_infile
    i_begin_col             = ‘1&#8242;
    i_begin_row             = ‘2&#8242;  “Do not require headings
    i_end_col               = ‘14&#8242;
    i_end_row               = ‘31&#8242;
    tables
    intern                  = itab
    exceptions
    inconsistent_parameters = 1
    upload_ole              = 2
    others                  = 3.
    if sy-subrc <> 0.
    message e010(zz) with text-001. “Problem uploading Excel Spreadsheet
    endif.
    Sort table by rows and colums
    sort itab by row col.
    Get first row retrieved
    read table itab index 1.
    Set first row retrieved to current row
    gd_currentrow = itab-row.
    loop at itab.
      Reset values for next row
    if itab-row ne gd_currentrow.
    append wa_record to it_record.
    clear wa_record.
    gd_currentrow = itab-row.
    endif.
    case itab-col.
    when ‘0001&#8242;.                              “First name
    wa_record-name1 = itab-value.
    when ‘0002&#8242;.                              “Surname
    wa_record-name2 = itab-value.
    when ‘0003&#8242;.                              “Age
    wa_record-age   = itab-value.
    endcase.
    endloop.
    append wa_record to it_record.
    *!! Excel data is now contained within the internal table IT_RECORD
    Display report data for illustration purposes
    loop at it_record into wa_record.
    write:/     sy-vline,
    (10) wa_record-name1, sy-vline,
    (10) wa_record-name2, sy-vline,
    (10) wa_record-age, sy-vline.
    endloop.

  • CRM ABAP How to upload an Excel file into an internal table?

    How to upload an Excel file using GUI_UPLOAD?? what should be the values of the parameters? The function modules ALSM_EXCEL_TO_INTERNAL_TABLE and KCD_EXCEL_OLE_TO_INT are not present in CRM. Please suggest me a way out!

    Hi saurabh,
    you can try the folowing sample..
    and make modifications according to your requirement..
    TYPE-POOLS: truxs.
    DATA: i_text_data TYPE truxs_t_text_data,
    v_filename_string TYPE string.
    DATA: BEGIN OF itab OCCURS 0,
    Name(30),
    Phone(15),
    Fax(500).
    DATA: END OF itab.
    PARAMETERS: p_file LIKE rlgrap-filename.
    START-OF-SELECTION.
    v_filename_string = p_file.
    CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
    filename = v_filename_string
    filetype = 'ASC'
    has_field_separator = 'X'
    * HEADER_LENGTH = 0
    * READ_BY_LINE = 'X'
    dat_mode = ''
    * IMPORTING
    * FILELENGTH =
    * HEADER =
    TABLES
    data_tab = i_text_data
    EXCEPTIONS
    file_open_error = 1
    file_read_error = 2
    no_batch = 3
    gui_refuse_filetransfer = 4
    invalid_type = 5
    no_authority = 6
    unknown_error = 7
    bad_data_format = 8
    header_not_allowed = 9
    separator_not_allowed = 10
    header_too_long = 11
    unknown_dp_error = 12
    access_denied = 13
    dp_out_of_memory = 14
    disk_full = 15
    dp_timeout = 16
    OTHERS = 17.
    IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
    i_field_seperator = 'X'
    * I_LINE_HEADER =
    i_tab_raw_data = i_text_data
    i_filename = p_file
    TABLES
    i_tab_converted_data = itab
    EXCEPTIONS
    conversion_failed = 1
    OTHERS = 2.
    IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    this is a sample code that uploads a excel file using GUI_UPLOAD, but uses another function module to convert that uploaded data into an internal table..
    regards
    satesh

  • How to upload  a excel file in webdynpro? Please help!

    Hi Experts,
        I have a requirement where I need to upload a  excel file in my webdynpro for ABAP report.
        I have used the fileupload UI element in my view and a upload button.
        However when I test the application I found that it is getting file data as some junk value like below:
        ###ࡱ#################>########################################################################################################################################################################################################################################
      Why is that so?
      Is there any limitation with fileuplaod reading excel file?
      Do i have to use any encoding option?
      What is the alternative option to read excel file in ABAP webdynpro?
    Thanks
    Gopal

    Hi,
    Check this.. Write this code in Upload button 's method
    ********** Reading data from flat file ****************
      DATA lo_el_context TYPE REF TO if_wd_context_element.
      DATA ls_context    TYPE wd_this->element_context.
      DATA lv_datasource type xstring.
    * get element via lead selection
      lo_el_context = wd_context->get_element(  ).
    * get single attribute
      lo_el_context->get_attribute(
        EXPORTING
          name =  `DATASOURCE`
        IMPORTING
          value = lv_datasource ).
       CALL FUNCTION 'HR_KR_XSTRING_TO_STRING'
        EXPORTING
    *   FROM_CODEPAGE       = '8500'
          IN_XSTRING          = LV_DATASOURCE
    *   OUT_LEN             = '1'
       IMPORTING
         OUT_STRING          = LV_STRING.
    SPLIT LV_STRING AT CL_ABAP_CHAR_UTILITIES=>NEWLINE INTO TABLE IT_STR.
      LOOP AT IT_STR INTO LV_STRING.
        SPLIT LV_STRING AT CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB INTO TABLE FIELDS.
        READ TABLE FIELDS INTO LV_FIELD INDEX 1.                 " Reading 1st field
        ls_header-STATU = LV_FIELD.
         clear LV_FIELD.
        READ TABLE FIELDS INTO LV_FIELD INDEX 2.                " Reading 2st field
         ls_header-LIFNR = LV_FIELD.
         clear LV_FIELD.
        READ TABLE FIELDS INTO LV_FIELD INDEX 3.
         ls_header-BSART = LV_FIELD.
         clear LV_FIELD.
        READ TABLE FIELDS INTO LV_FIELD INDEX 4.
         ls_header-EKORG = LV_FIELD.
         clear LV_FIELD.
        READ TABLE FIELDS INTO LV_FIELD INDEX 5.
         ls_header-EKGRP = LV_FIELD.
         clear LV_FIELD.
        READ TABLE FIELDS INTO LV_FIELD INDEX 6.
         ls_header-BUKRS = LV_FIELD.
         clear LV_FIELD.
         APPEND wa to it.
        append ls_header to lt_header.
        clear: ls_header,wa.
        endloop.
        lo_nd_header->BIND_TABLE( lt_header ).
    Thanks,
    Ramesh
    Edited by: Rameshkumar Raamasamy on Dec 20, 2010 11:16 AM

  • Can anybody help how to upload an excel file into sap-crm urgent

    hi guys,
    i need the right function module to upload the excel file from the presentation server in to sap-crm.
    1) I know we use the function module 'ALSM_EXCEL_TO_INT_TABLE' in sap-r/3 but this function module is not exist in sap-crm.
    2) i tried with the function moduel 'GUI_UPLOAD' but its not uploading correctly i am gettting hases(#).
    Please can any one provide the right function module to upload the excel into sap-crm with an sample code.
    thanks
    viswa guntha

    Hi Visma,
    Please check this link for sample custom FM.
    Re: function mudule for MS excel file to sap crm
    Hope this will help.
    Regards,
    Ferry Lianto
    Please reward points if helpful as away to say thanks.

  • How to upload a excel file using BDC

    how should i upload a file using BDC
    i have downloaded a excel file containing the values of  table A006 a X server.
    now i hav to upload it into new server Y server using BDC , how do i do it?
    wat all things one shud consider ?

    Hi,
    This is very simple, follow the below mention steps to do so:
    1.Declare an internal table having same structure as db table, but take all the fields type as 'C' and length same as defined in the table.
    TYPES:BEGIN OF it,
      key(20) TYPE c,
      indicator(20) TYPE c,
      bldat(20) TYPE c,"bkpf-bldat
      budat(20) TYPE c,"bkpf-budat
      END OF it.
    DATA: itab TYPE STANDARD TABLE OF it,
          wa TYPE it.
    2.Include TRUX as type pool and declare a variable of type trux_t_text_data to be passed in the FM that actually reads data from excel sheet into above declared intrenal table.
    TYPE-POOLS: truxs.
    DATA: it_raw TYPE truxs_t_text_data.
    3. Call the FM 'TEXT_CONVERT_XLS_TO_SAP' and pass the file name and the internal table name into the parameter
    CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
        EXPORTING
    *    I_FIELD_SEPERATOR          = 'X'
         i_line_header              = 'X'
          i_tab_raw_data             = it_raw
          i_filename                 = p_file "name of the excel file
        TABLES
          i_tab_converted_data       = itab[] "internal table where data will be stored
       EXCEPTIONS
         conversion_failed          = 1
         OTHERS                     = 2
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    4. loop at internal table and modify the ztable/dbtable where data to be upload .
    Hope this solve your problem.
    Pooja

  • How to upload all excel files data from one folder into internal table.

    Dear All,
    I have one requirement, It is like I want to upload the frontend file data into my internal table, But here my scenario is;
    If I have one folder ( Called : Temp) in my frontend system, in this folder ( Called : Temp)  I have 100 excel files. In each excel file I have some 1000u2019s of entries. All these data of every file I want to take into my internal table.
    If I have one file I can go for, CALL METHOD cl_gui_frontend_services=>file_open_dialog and then upload method to upload. But I want to take all these excel files from that folder at a time, is there any class or any thing is there..? plz help..
    Thanks...
    Edited by: satishsuri on Jan 11, 2011 9:33 AM

    Hi satishsuri ,
    You will have to use 3 methods together :
    CALL METHOD cl_gui_frontend_services=>directory_browse "Browse the Directory
    CALL METHOD cl_gui_frontend_services=>directory_list_files "Get all the files from the directory
    CALL METHOD cl_gui_frontend_services=>gui_upload "Upload each file in a loop
    Example:
    TYPES: BEGIN OF ty_data,
             line TYPE string,
          END OF ty_data.
    DATA: str_file TYPE string,
          str_dir TYPE string,
          it_file_table TYPE STANDARD TABLE OF file_info,
          wa_file_table TYPE file_info,
          v_count TYPE i,
          it_data TYPE STANDARD TABLE OF ty_data,
          wa_data TYPE ty_data.
    CALL METHOD cl_gui_frontend_services=>directory_browse
      CHANGING
        selected_folder = str_dir.
    CALL METHOD cl_gui_frontend_services=>directory_list_files
      EXPORTING
        directory  = str_dir
      CHANGING
        file_table = it_file_table
        count      = v_count.
    LOOP AT it_file_table INTO wa_file_table.
      CONCATENATE str_dir wa_file_table-filename INTO str_file SEPARATED BY '\'.
      CALL METHOD cl_gui_frontend_services=>gui_upload
        EXPORTING
          filename = str_file
          filetype = 'ASC'
        CHANGING
          data_tab = it_data.
      LOOP AT it_data INTO wa_data.
        WRITE : / wa_data-line.
      ENDLOOP.
      ULINE.
    ENDLOOP.
    Regards,
    Jovito

  • Pls tell me how to upload from excel file to database.

    hello,experts,
    I want to upload data from excel local file to database table created by myself.when I use function
    CALL FUNCTION 'GUI_DOWNLOAD'
    the data in the internal table just become error code data that can not understand.
    who can help me out?
    thanks.

    Hi,
    1st copy the values in XLS into internal table by using function Module:-
    call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    exporting
    filename = file_name<it is file path of u r XLS>
    i_begin_col = 1
    i_begin_row = 1
    i_end_col = 250
    i_end_row = 1
    tables
    intern = itab<this structure is same like u r database table>
    exceptions
    inconsistent_parameters = 1
    upload_ole = 2
    others = 3.
    if sy-subrc 0.
    then modify or insert these values to database from internal table:-
    modify <DB table> from itab accepting duplicate keys.
    for file popup use :
    at selection-scree on <screen field>.
    call function 'F4_FILENAME'
    exporting
       program = sy-cprog
       dynnr     = sy-dynnr
    importing
       filename = zfilename.
    here zfilename of type rlgrap-filename.
    and pass this as path in ASLA_EXCEL_TO_INTERNAL_TABLE
    Edited by: vijay Mekala on Dec 29, 2007 12:45 PM

  • Uploading data from an excel file to ztable

    Hi,
    I tried to upload an excel file to ztable using fm 'ALSM_EXCEL_TO_INTERNAL_TABLE'.In the o/p I can see only 3 rows and all the date and time fields are not properly displayed in the o/p.What would be the reason?Can anyone give me a suggestion?
    Regards,
    Hema

    Hi,
    pls check my code.
                       Data Definitions                                  *
      Internal Tables
    DATA : t_zrb_hdr TYPE STANDARD TABLE OF ZRB_HDR WITH HEADER LINE,
           t_field_catalog  TYPE slis_t_fieldcat_alv.
    Declaration of the Internal Table with Header Line comprising of the uploaded data.
    DATA: BEGIN OF t_file_upload OCCURS 0.
    INCLUDE STRUCTURE ALSMEX_TABLINE. " Rows for Table with Excel Data
    DATA: END OF t_file_upload.
    form UPLOAD_EXCEL_FILE .
    CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
      EXPORTING
        filename                      = p_file
        i_begin_col                   = '1'
        i_begin_row                   = '2'
        i_end_col                     = '10'
        i_end_row                     = '250'
      tables
        intern                        = t_file_upload
    EXCEPTIONS
      INCONSISTENT_PARAMETERS       = 1
      UPLOAD_OLE                    = 2
      OTHERS                        = 3
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

  • How to Upload the excel flat file in LSMW

    Hi all,
    Can any one plz Help me,
    How to Upload a excel file format by suing the lsmw .
    Regadrs.
    [email protected]
    Upender..
    Edited by: Upender Reddy on Sep 12, 2008 8:37 AM

    Hi,
    In 7 th step of LSMW we need to specify the file ie flat file.
    In this step you describe all files to be used in the following steps:
    · Your legacy data on the PC and/or R/3 server
    · The file for the read data
    · The file for the converted data.
    As your legacy data is on the PC: ie your excel file that is tab delimited or comma delimited.
    here give ur file name, description , click data from one src structure, then delimiter is tabulator if so, in file structure click both check boxes if in ur flat file ur first row is column, file type is record end indicator, code page ASCII and conitnue that's it.
    you can go through this link very useful :
    ****************/Tutorials/LSMW/LSMWMainPage.htm.
    thanx.

  • How to upload an excel template file to SAP server

    Dear Experts,
    I am develpoing a program to generate the Excel file with a fixed template and save it to user's local drive, the excel template is stored in SAP server. I use the function module C13Z_FILE_DOWNLOAD_BINARY to do this is. But now my problem is I do not know how to upload the excel template to our SAP server. Do any friends can kindly tell me how to upload the excel template to SAP server?? Thanks.
    Best Regards
    Joe

    Hi Joe,
    Please refer following sample program:
    http://abapcode.blogspot.com/2007/06/sample-program-to-upload-excel-document.html
    Best regards,
    Prashant

  • Excel file to Ztable

    Hi,
    I have 2 upload data of 1,000 rows from excel sheet to my Ztable. How to write code for it.
    thanks & regards
    ram

    Check the below program and here uploading the data from excel file to Ztable
    REPORT ZLWMI151_UPLOAD no standard page heading
                           line-size 100 line-count 60.
    *tables : zbatch_cross_ref.
    data : begin of t_text occurs 0,
           werks(4) type c,
           cmatnr(15) type c,
           srlno(12) type n,
           matnr(7) type n,
           charg(10) type n,
           end of t_text.
    data: begin of t_zbatch occurs 0,
          werks like zbatch_cross_ref-werks,
          cmatnr like zbatch_cross_ref-cmatnr,
          srlno like zbatch_cross_ref-srlno,
          matnr like zbatch_cross_ref-matnr,
          charg like zbatch_cross_ref-charg,
          end of t_zbatch.
    data : g_repid like sy-repid,
           g_line like sy-index,
           g_line1 like sy-index,
           $v_start_col         type i value '1',
           $v_start_row         type i value '2',
           $v_end_col           type i value '256',
           $v_end_row           type i value '65536',
           gd_currentrow type i.
    data: itab like alsmex_tabline occurs 0 with header line.
    data : t_final like zbatch_cross_ref occurs 0 with header line.
    selection-screen : begin of block blk with frame title text.
    parameters : p_file like rlgrap-filename obligatory.
    selection-screen : end of block blk.
    initialization.
      g_repid = sy-repid.
    at selection-screen on value-request for p_file.
      CALL FUNCTION 'F4_FILENAME'
           EXPORTING
                PROGRAM_NAME = g_repid
           IMPORTING
                FILE_NAME    = p_file.
    start-of-selection.
    Uploading the data into Internal Table
      perform upload_data.
      perform modify_table.
    top-of-page.
      CALL FUNCTION 'Z_HEADER'
      EXPORTING
        FLEX_TEXT1       =
        FLEX_TEXT2       =
        FLEX_TEXT3       =
    *&      Form  upload_data
          text
    FORM upload_data.
      CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
           EXPORTING
                FILENAME                = p_file
                I_BEGIN_COL             = $v_start_col
                I_BEGIN_ROW             = $v_start_row
                I_END_COL               = $v_end_col
                I_END_ROW               = $v_end_row
           TABLES
                INTERN                  = itab
           EXCEPTIONS
                INCONSISTENT_PARAMETERS = 1
                UPLOAD_OLE              = 2
                OTHERS                  = 3.
      IF SY-SUBRC <> 0.
        write:/10 'File '.
      ENDIF.
      if sy-subrc eq 0.
        read table itab index 1.
        gd_currentrow = itab-row.
        loop at itab.
          if itab-row ne gd_currentrow.
            append t_text.
            clear t_text.
            gd_currentrow = itab-row.
          endif.
          case itab-col.
            when '0001'.
              t_text-werks = itab-value.
            when '0002'.
              t_text-cmatnr = itab-value.
            when '0003'.
              t_text-srlno = itab-value.
            when '0004'.
              t_text-matnr = itab-value.
            when '0005'.
              t_text-charg = itab-value.
          endcase.
        endloop.
      endif.
      append t_text.
    ENDFORM.                    " upload_data
    *&      Form  modify_table
          Modify the table ZBATCH_CROSS_REF
    FORM modify_table.
      loop at t_text.
        t_final-werks = t_text-werks.
        t_final-cmatnr = t_text-cmatnr.
        t_final-srlno = t_text-srlno.
        t_final-matnr = t_text-matnr.
        t_final-charg = t_text-charg.
        t_final-erdat = sy-datum.
        t_final-erzet = sy-uzeit.
        t_final-ernam = sy-uname.
        t_final-rstat = 'U'.
        append t_final.
        clear t_final.
      endloop.
      delete t_final where werks = ''.
      describe table t_final lines g_line.
      sort t_final by werks cmatnr srlno.
    Deleting the Duplicate Records
      perform select_data.
      describe table t_final lines g_line1.
      modify zbatch_cross_ref from table t_final.
      if sy-subrc ne 0.
        write:/ 'Updation failed'.
      else.
        Skip 1.
        Write:/12 'Updation has been Completed Sucessfully'.
        skip 1.
        Write:/12 'Records in file ',42 g_line .
        write:/12 'Updated records in Table',42 g_line1.
      endif.
      delete from zbatch_cross_ref where werks = ''.
    ENDFORM.                    " modify_table
    *&      Form  select_data
          Deleting the duplicate records
    FORM select_data.
      select werks
             cmatnr
             srlno from zbatch_cross_ref
             into table t_zbatch for all entries in t_final
             where werks = t_final-werks
             and  cmatnr = t_final-cmatnr
             and srlno = t_final-srlno.
      sort t_zbatch by werks cmatnr srlno.
      loop at t_zbatch.
        read table t_final with key werks = t_zbatch-werks
                                    cmatnr = t_zbatch-cmatnr
                                    srlno = t_zbatch-srlno.
        if sy-subrc eq 0.
          delete table t_final .
        endif.
        clear: t_zbatch,
               t_final.
      endloop.
    ENDFORM.                    " select_data
    Thanks
    Seshu

  • To upload a excel file to dB table through webdynpro ABAP

    HI,
        I am unable to upload a excel file directly by using  func module   "HR_KR_XSTRING_TO_STRING".
        If file is in tab delimited then only, I am able to upload.
        Suggest me if there are any other options to upload a excel file.

    Hi,
    The below link gives you an explanation of how you can upload an excel file to web dynpro.
    http://www.****************/Tutorials/WebDynproABAP/Upload/Page1.htm
    Kindly read go through the below link, as this issue have been brought up before
    http://forums.sdn.sap.com/thread.jspa?threadID=1831838
    Thanks and regards.
    Edited by: Suraj Ravindran Nair on Feb 24, 2012 6:24 AM

  • Need help in uploading an excel file into SAP

    Hi All,
    I got a requirement to upload an excel file to SAP.
    But When i tried with the FM "ALSM_EXCEL_TO_INTERNAL_TABLE" , file  not getting uploaded to internal table.
    Getting expection 2, UPLOAD_OLE...
    I think the problem is with the file... the following the sample text of the file...
    Technical IdentNo.     Line No.     Text                                 Location
    BS-PZ-180                   1     035-05 EXZENTER-SCHNECKENPUMPE             0026
    BS-PZ-180                   2          LIEFERANT : SOCSIL-INTER SA  ECUBLENS     0026
    BS-PZ-180                   3          HERSTELLER : MONO PUMPS LIMITED  MANCH     0026
    BS-PZ-180                   4          MODELL/TYP : SH 60                             0026
    But when I tried with only one Column..its getting successfully uploaded...
    Pls suggest me how to upload the file? ( May be with sample code)
    Also pls let me know hw to handle the file..which contains 5 differnt sheets of texts.. ( May be with sample code)
    Your suggestion will be highly appreciated...
    Thanks,
    Priya

    Hi,
    Use the FM: TEXT_CONVERT_XLS_TO_SAP.  It will work perfectly.  I used this function module and uploaded data from xls to sap.  check the following code:
    TYPE-POOLS: truxs.
    PARAMETERS: p_file TYPE  rlgrap-filename.
    TYPES: BEGIN OF t_datatab,
          PROP_NAME like SDOKPROP-PROP_NAME,
          PROP_CHECK like SDOKPROP-PROP_CHECK,
          TABNAME like SDOKPROP-TABNAME,
          FIELDNAME like SDOKPROP-FIELDNAME,
          DESCRIPT(30) type c,
          END OF t_datatab.
    DATA: it_datatab type standard table of t_datatab,
          itab  TYPE STANDARD TABLE OF t_datatab,
          wa_itab TYPE t_datatab,
          wa_datatab type t_datatab.
    DATA: it_raw TYPE truxs_t_text_data.
    At selection screen
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
      CALL FUNCTION 'F4_FILENAME'
        EXPORTING
          field_name = 'P_FILE'
        IMPORTING
          file_name  = p_file.
    *START-OF-SELECTION.
    START-OF-SELECTION.
    SELECT * FROM sdokprop INTO CORRESPONDING FIELDS OF TABLE itab
    WHERE PROP_NAME LIKE 'DMS%'.
    WRITE / 'Before Modification'.
      LOOP AT itab INTO wa_itab.
        WRITE:/1 wa_itab-PROP_NAME, 27 wa_itab-PROP_CHECK, 31 wa_itab-TABNAME, 65 wa_itab-FIELDNAME, 96 wa_itab-DESCRIPT.
        CLEAR wa_itab.
      ENDLOOP.
      CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
        EXPORTING
        I_FIELD_SEPERATOR        =
          i_line_header            =  'X'
          i_tab_raw_data           =  it_raw       " WORK TABLE
          i_filename               =  p_file
        TABLES
          i_tab_converted_data     = it_datatab[]    "ACTUAL DATA
       EXCEPTIONS
          conversion_failed        = 1
          OTHERS                   = 2.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    END-OF-SELECTION.
    END-OF-SELECTION.
      WRITE / 'After Modification'.
    MODIFY sdokprop FROM TABLE it_datatab.
      LOOP AT it_datatab INTO wa_datatab.
        WRITE:/1 wa_datatab-PROP_NAME, 27 wa_datatab-PROP_CHECK, 31 wa_datatab-TABNAME, 65 wa_datatab-FIELDNAME, 96 wa_datatab-DESCRIPT.
        CLEAR wa_datatab.
      ENDLOOP.
      IF sy-subrc = 0.
        MESSAGE 'successfull' TYPE 'S'.
      ELSE.
        MESSAGE 'failed' TYPE 'E'.
      ENDIF.
    Regards,
    Bhaskar

  • Help with uploading an excel file to a table using an application

    Hello,
    Can anyone please help me out with this issue. I have apex application where in the end users upload an excel file to a table. For this I have followed the solution provided in this link
    http://avdeo.com/2008/05/21/uploading-excel-sheet-using-oracle-application-express-apex/
    Using the above solution, I was able to upload the excel data to a table "sample_tbl1" successfully with fields Id,acct_no,owner_name,process_dt. But the thing is I want accomdate a particular condition while uploading the file data, to check see if the acct_no already exists in another table say "sample_tbl2" or not. If acct_nos already exists in sample_tbl2 then give out an error displaying the list of account numbers that already exists in the database. Below is the code which I am using to upload file data to a table.
    DECLARE
    v_blob_data       BLOB; 
    v_blob_len        NUMBER; 
    v_position        NUMBER; 
    v_raw_chunk       RAW(10000); 
    v_char            CHAR(1); 
    c_chunk_len       number       := 1; 
    v_line            VARCHAR2 (32767)        := NULL; 
    v_data_array      wwv_flow_global.vc_arr2; 
    v_rows            number; 
    v_sr_no           number         := 1; 
    l_cnt             BINARY_INTEGER := 0;
    l_stepid          NUMBER := 10;
    BEGIN
    --Read data from wwv_flow_files</span> 
    select blob_content into v_blob_data 
    from wwv_flow_files 
    where last_updated = (select max(last_updated) from wwv_flow_files where UPDATED_BY = :APP_USER) 
    and id = (select max(id) from wwv_flow_files where updated_by = :APP_USER); 
    v_blob_len := dbms_lob.getlength(v_blob_data); 
    v_position := 1; 
    /* Evaluate and skip first line of data
    WHILE (v_position <= v_blob_len ) LOOP
    v_raw_chunk := dbms_lob.substr(v_blob_data,c_chunk_len,v_position);
    v_char :=  chr(hex_to_decimal(rawtohex(v_raw_chunk)));
    v_line := v_line || v_char;
    v_position := v_position + c_chunk_len;
    -- When a whole line is retrieved
    IF v_char = CHR(10) THEN
    -- Clear out 
    v_line := NULL;
    EXIT;
    END IF;
    END LOOP;
    -- Read and convert binary to char</span> 
    WHILE ( v_position <= v_blob_len ) LOOP 
    v_raw_chunk := dbms_lob.substr(v_blob_data,c_chunk_len,v_position); 
    v_char :=  chr(hex_to_decimal(rawtohex(v_raw_chunk))); 
    v_line := v_line || v_char; 
    v_position := v_position + c_chunk_len; 
    -- When a whole line is retrieved </span> 
    IF v_char = CHR(10) THEN
    -- Convert comma to : to use wwv_flow_utilities </span> 
    v_line := REPLACE (v_line, ',', ':'); 
    -- Convert each column separated by : into array of data </span> 
    v_data_array := wwv_flow_utilities.string_to_table (v_line); 
    -- Insert data into target table
    EXECUTE IMMEDIATE 'insert into sample_tbl1(ID,ACCT_NO,OWNER_NAME,PROCESS_DT) 
    values (:1,:2,:3,:4)'
    USING 
    v_sr_no, 
    v_data_array(1), 
    v_data_array(2),
    to_date(v_data_array(3),'MM/DD/YYYY');
    -- Clear out 
    v_line := NULL; 
    v_sr_no := v_sr_no + 1; 
    l_cnt := l_cnt + SQL%ROWCOUNT;
    END IF; 
    END LOOP;
    delete from wwv_flow_files
    where last_updated = (select max(last_updated) from wwv_flow_files where UPDATED_BY = :APP_USER)
    and id = (select max(id) from wwv_flow_files where updated_by = :APP_USER);
    l_stepid  := 20;
    IF l_cnt = 0 THEN
    apex_application.g_print_success_message := apex_application.g_print_success_message || '<p><span style="font-size:14;font-weight:bold">Please select a file to upload.</span></p>' ;
    ELSE
    apex_application.g_print_success_message := apex_application.g_print_success_message || '<p><span style="font-size:14;font-weight:bold;color:green">File uploaded and processed ' || l_cnt || ' record(s) successfully.</span></p>';
    END IF;
    l_stepid  := 30;
    EXCEPTION WHEN OTHERS THEN
    ROLLBACK;
    apex_application.g_print_success_message := apex_application.g_print_success_message || '<p><span style="font-size:14;font-weight:bold;color:red">Failed to upload the file. '||REGEXP_REPLACE(SQLERRM,'[('')(<)(>)(,)(;)(:)(")('')]{1,}', '') ||'</span></p>';
    END;
    {code}
    Can anyone please help me, how do i accomdate the condition within my existing code.
    thanks,
    Orton                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Orton,
    From your code it appears that the account No comes in the second column of the file = > v_data_array(1)
    So You can put a conditional block around the execute immediate code that inserts the records
    For instance
      SELECT count(1) INTO ln_account_no_exists from <"sample_tbl2> where account_no = v_data_array(1);
      IF (  ln_account_no_exists > 0 ) THEN
         --Account No: already exists
        <Do what you want to do here >
      ELSE
        EXECUTE IMMEDIATE ...
      END IF:
    {code}
    Inorder to handle the account no records which exists you can
      <li>Raise an exception
      <li> Write record to table or insert into collection and then use a report region in the page based on this table/collection to show error records
      <li> Append errored account No:s to the Success Message Variable programmatically(this variable is used by PLSQL process success/error message )
       {code}
        IF ( record exists)
          apex_application.g_print_success_message := apex_application.g_print_success_message||','|| v_data_array(1) ; -- Comma separated list of errored account no:s
        ELSE ...
       {code}
    Hope it helps                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Maybe you are looking for