How to retrieve data from a read-only Excel file

Hi Developers,
I'm trying to retrieve data from a read-only Excel file. I used the same code that I used to retrieve data from a normal Excel file, but it can't work.
My code is as followed:
try
InputStream KpExcel = new FileInputStream("kp.xls");
HSSFWorkbook Kpwb = new HSSFWorkbook(KpExcel);
HSSFSheet Kpsheet = Kpwb.getSheetAt(0);
catch(Exception e)
e.printStackTrace();
System.out.println("Exception: "+e.getMessage());
The error I received is as followed:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
at org.apache.poi.hssf.record.RecordFactory.createRecord(RecordFactory.java:224)
at org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:160)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:163)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:210)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:191)
at photoproductionsystem.IncomingWIPPanel.getKp(IncomingWIPPanel.java:118)
at photoproductionsystem.IncomingWIPPanel.<init>(IncomingWIPPanel.java:76)
at photoproductionsystem.TabbedDisplay.<init>(TabbedDisplay.java:47)
at photoproductionsystem.Display.create(Display.java:73)
at photoproductionsystem.Display.init(Display.java:44)
at photoproductionsystem.Display.main(Display.java:229)
Caused by: java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
at org.apache.poi.hssf.record.UnknownRecord.<init>(UnknownRecord.java:62)
at org.apache.poi.hssf.record.SubRecord.createSubRecord(SubRecord.java:57)
at org.apache.poi.hssf.record.ObjRecord.fillFields(ObjRecord.java:99)
at org.apache.poi.hssf.record.Record.fillFields(Record.java:90)
at org.apache.poi.hssf.record.Record.<init>(Record.java:55)
at org.apache.poi.hssf.record.ObjRecord.<init>(ObjRecord.java:61)
... 15 more
Can someone please help me with my problem? Thanks a lot in advance!

Madeline wrote:
how do I ask at Apache mailing list?I wonder why it seems to be a strange idea to some people to look at the software vendor's site for product support. :p
http://poi.apache.org/mailinglists.html

Similar Messages

  • How to Downlaod Data from Alv List to Excel File

    Hi,
      I have a Requirement like While download data from ALV to Excel File .After Download data into Excel we will not allow user to edit the Excel data..
    Plz  help me to complete this scenario.
    Thanks & Regards,
    Kumaran Duraiswamy.

    hi,
    try these following fm's
    MS_EXCEL_OLE_STANDARD_DAT
    EXCEL_OLE_STANDARD_DAT
    CALL FUNCTION 'MS_EXCEL_OLE_STANDARD_DAT'
    EXPORTING
    file_name = 'Your Path' " enter your path to save the file.
    CREATE_PIVOT = 0
    * DATA_SHEET_NAME = ' '
    * PIVOT_SHEET_NAME = ' '
    * PASSWORD = ' '
    * PASSWORD_OPTION = 0
    VISIBLE = '0'
    No_DIALOG = 'X'
    TABLES
    * PIVOT_FIELD_TAB =
    DATA_TAB = t_deli_final
    * FIELDNAMES =
    EXCEPTIONS
    FILE_NOT_EXIST = 1
    FILENAME_EXPECTED = 2
    COMMUNICATION_ERROR = 3
    OLE_OBJECT_METHOD_ERROR = 4
    OLE_OBJECT_PROPERTY_ERROR = 5
    INVALID_FILENAME = 6
    INVALID_PIVOT_FIELDS = 7
    DOWNLOAD_PROBLEM = 8
    OTHERS = 9
    IF sy-subrc 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    2nd fm
      CALL FUNCTION 'EXCEL_OLE_STANDARD_DAT'
           EXPORTING
                FILE_NAME                 = 'Your Path' "path to save your file
                DATA_SHEET_NAME           = V_SHEET_NAME
           TABLES
                DATA_TAB                  = TLX
           EXCEPTIONS
                FILE_NOT_EXIST            = 1
                FILENAME_EXPECTED         = 2
                COMMUNICATION_ERROR       = 3
                OLE_OBJECT_METHOD_ERROR   = 4
                OLE_OBJECT_PROPERTY_ERROR = 5
                INVALID_FILENAME          = 6
                INVALID_PIVOT_FIELDS      = 7
                DOWNLOAD_PROBLEM          = 8
                OTHERS                    = 9.
      IF SY-SUBRC NE 0.
        WRITE:/ 'ERROR OPENING EXCEL'.
      ENDIF.
    ELSE.
      WRITE:/ 'ERROR OR NO DATA'.
    ENDIF.

  • How to download data from different sheet of excel file.

    Hi Friends,
    I have a Excel file with different sheet like sheet 1, sheet 2 and so on,
    and i have to download each sheet data in to different internal tables.
    Is there any FM or something else.
    Pl. help
    Thanks
    Sunil.

    Hi,
       You can create the function module for this.
    The code sample is as below:
    *Code Sample *
    FUNCTION Z_UPLOADING_FROM_2SHEETS.
    ""Local interface:
    *" IMPORTING
    *" VALUE(FILE_NAME) LIKE RLGRAP-FILENAME
    *" VALUE(START_ROW_SHEET1) TYPE I
    *" VALUE(START_COLUMN_SHEET1) TYPE I
    *" VALUE(START_ROW_SHEET2) TYPE I
    *" VALUE(START_COLUMN_SHEET2) TYPE I
    *" VALUE(END_ROW_SHEET1) TYPE I
    *" VALUE(END_COLUMN_SHEET1) TYPE I
    *" VALUE(END_ROW_SHEET2) TYPE I
    *" VALUE(END_COLUMN_SHEET2) TYPE I
    *" TABLES
    *" IT_DATA1 STRUCTURE ALSMEX_TABLINE
    *" IT_DATA2 STRUCTURE ALSMEX_TABLINE
    *" EXCEPTIONS
    *" INCONSISTENT_PARAMETERS
    *" UPLOAD_OLE
    DATA DECLARATION
    DATA: excel_tab TYPE ty_t_sender,
    excel_tab1 TYPE ty_t_sender.
    DATA: ld_separator TYPE c.
    DATA: application TYPE ole2_object,
    workbook TYPE ole2_object,
    SHEET TYPE OLE2_OBJECT,
    range TYPE ole2_object,
    worksheet TYPE ole2_object.
    DATA: h_cell TYPE ole2_object,
    h_cell1 TYPE ole2_object.
    DATA: ld_rc TYPE i.
    MESSAGE DEFINATION
    DEFINE m_message.
    case sy-subrc.
    when 0.
    when 1.
    message id sy-msgid type sy-msgty number sy-msgno
    with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    when others. raise upload_ole.
    endcase.
    END-OF-DEFINITION.
    PARAMETER CHECK
    IF START_ROW_SHEET1 > END_ROW_SHEET1.
    RAISE inconsistent_parameters.
    ENDIF.
    IF START_COLUMN_SHEET1 > END_COLUMN_SHEET1.
    RAISE inconsistent_parameters.
    ENDIF.
    IF START_ROW_SHEET2 > END_ROW_SHEET2.
    RAISE inconsistent_parameters.
    ENDIF.
    IF START_COLUMN_SHEET2 > END_COLUMN_SHEET2.
    RAISE inconsistent_parameters.
    ENDIF.
    CLASS cl_abap_char_utilities DEFINITION LOAD.
    ld_separator = cl_abap_char_utilities=>horizontal_tab.
    OPENING EXCEL FILE
    IF application-header = space OR application-handle = -1.
    CREATE OBJECT application 'Excel.Application'.
    m_message.
    ENDIF.
    CALL METHOD OF APPLICATION 'Workbooks' = WORKBOOK.
    m_message.
    CALL METHOD OF application 'Workbooks' = workbook.
    m_message.
    CALL METHOD OF workbook 'Open' EXPORTING #1 = FILE_NAME.
    m_message.
    CALL METHOD OF APPLICATION 'Worksheets' = SHEET EXPORTING #1 = 1.
    m_message.
    CALL METHOD OF APPLICATION 'Worksheets' = SHEET EXPORTING #1 = 1.
    m_message.
    CALL METHOD OF SHEET 'Activate'.
    m_message.
    GET PROPERTY OF application 'ACTIVESHEET' = sheet.
    m_message.
    MARKING OF WHOLE SPREADSHEET
    CALL METHOD OF sheet 'Cells' = h_cell
    EXPORTING #1 = START_ROW_SHEET1 #2 = START_COLUMN_SHEET1.
    m_message.
    CALL METHOD OF sheet 'Cells' = h_cell1
    EXPORTING #1 = END_ROW_SHEET1 #2 = END_COLUMN_SHEET1.
    m_message.
    CALL METHOD OF sheet 'RANGE' = range
    EXPORTING #1 = h_cell #2 = h_cell1.
    m_message.
    CALL METHOD OF range 'SELECT'.
    m_message.
    Copy marked area (SHEET1) into Clippboard
    CALL METHOD OF range 'COPY'.
    m_message.
    Read clipboard into ABAP
    CALL METHOD cl_gui_frontend_services=>clipboard_import
    IMPORTING
    data = excel_tab
    EXCEPTIONS
    cntl_error = 1
    ERROR_NO_GUI = 2
    NOT_SUPPORTED_BY_GUI = 3
    OTHERS = 4
    IF sy-subrc <> 0.
    MESSAGE a037(alsmex).
    ENDIF.
    PERFORM separated_to_intern_convert TABLES excel_tab IT_DATA1
    USING ld_separator.
    Clear the clipboard
    REFRESH excel_tab.
    CALL METHOD cl_gui_frontend_services=>clipboard_export
    IMPORTING
    data = excel_tab
    CHANGING
    rc = ld_rc
    EXCEPTIONS
    cntl_error = 1
    ERROR_NO_GUI = 2
    NOT_SUPPORTED_BY_GUI = 3
    OTHERS = 4
    Working in Second Excel Work Sheet
    CALL METHOD OF APPLICATION 'Worksheets' = SHEET EXPORTING #1 = 2.
    m_message.
    CALL METHOD OF SHEET 'Activate'.
    m_message.
    GET PROPERTY OF application 'ACTIVESHEET' = sheet.
    m_message.
    Mark Sheet2
    CALL METHOD OF sheet 'Cells' = h_cell
    EXPORTING #1 = START_ROW_SHEET2 #2 = START_COLUMN_SHEET2.
    m_message.
    CALL METHOD OF sheet 'Cells' = h_cell1
    EXPORTING #1 = END_ROW_SHEET2 #2 = END_COLUMN_SHEET2.
    m_message.
    CALL METHOD OF sheet 'RANGE' = range
    EXPORTING #1 = h_cell #2 = h_cell1.
    m_message.
    CALL METHOD OF range 'SELECT'.
    m_message.
    Copy Marked Area (Sheet2) into Clippboard
    CALL METHOD OF range 'COPY'.
    m_message.
    Read Clipboard into ABAP
    CALL METHOD cl_gui_frontend_services=>clipboard_import
    IMPORTING
    data = excel_tab1
    EXCEPTIONS
    cntl_error = 1
    ERROR_NO_GUI = 2
    NOT_SUPPORTED_BY_GUI = 3
    OTHERS = 4
    IF sy-subrc <> 0.
    MESSAGE a037(alsmex).
    ENDIF.
    PERFORM separated_to_intern_convert TABLES excel_tab1 IT_DATA2
    USING ld_separator.
    Clear Clipboard
    REFRESH excel_tab.
    CALL METHOD cl_gui_frontend_services=>clipboard_export
    IMPORTING
    data = excel_tab1
    CHANGING
    rc = ld_rc
    EXCEPTIONS
    cntl_error = 1
    ERROR_NO_GUI = 2
    NOT_SUPPORTED_BY_GUI = 3
    OTHERS = 4
    Leaving Application .
    CALL METHOD OF application 'QUIT'.
    m_message.
    FREE OBJECT application.
    m_message.
    ENDFUNCTION.

  • How to Retrieve data from Variant Table

    Can anyone help me by telling how to retrieve data from variant table which was created by user. I am able to see data of variant table only thru cu60 transaction but not se11. I s there any function module to do this?

    Hello Mohan,
    if u already have data and u want to populate it in F4 help then use below code -
    u Have to make use of FM - 'F4IF_INT_TABLE_VALUE_REQUEST'
    REPORT  ZGILL_VALUE_REQUEST                     .
    data: begin of lt_all occurs 0.
            include structure DYNPREAD.
    data  end of lt_all.
    data: begin of lt_selected occurs 0.
           include structure DDSHRETVAL.
    data: end of lt_selected.
    DATA: BEGIN OF lt_code OCCURS 0,
                code LIKE zgill_main-PERNR,
          END OF lt_code.
    data no_dyn like sy-dynnr.
    Parameters : ECODE like zgill_main-PERNR.
    *parameters: pernr like pa0001-pernr .
    no_dyn =  sy-dynnr.   "give the scren no directly or sy-dynnr in case of report.
    At selection-screen on value-request for ECODE.
    select PERNR into table lt_code from zgill_main.
      CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
          EXPORTING
            retfield               = 'ECODE'
            dynpprog               = sy-repid
           dynpnr                  = no_dyn
          dynprofield              =       'ECODE'
          window_title           = 'Employee Details'
           value_org              = 'S'
          DISPLAY                = 'F'
       TABLES
            value_tab             = lt_code
           RETURN_TAB             = lt_selected.
    EXCEPTIONS
      PARAMETER_ERROR        = 1
      NO_VALUES_FOUND        = 2
      OTHERS                 = 3
    *if sy-subrc eq '0' .
      write: 'success'.
    *endif.
    read   table lt_selected index sy-tabix.
    move lt_selected-fieldval to ECODE.

  • How to retrieve data from excel sheet

    Hi,
    How to retrieve data from excel sheet into a java file.

    janu05 wrote:
    If we append a $ in the end of the table name it is showing an error saying "invalid name,should not contain any invalid character or punctuation"Great, I'm very happy for you.
    Unless that was a question. In which case you might what to tell us a little more.
    Like which API you are using (assuming we are still on "reading an Excel sheet".

  • How to retrieve data from catsdb table and convert into xml using BAPI

    How to retrieve data from catsdb table and convert into xml using BAPI
    Points will be rewarded,
    Thank you,
    Regards,
    Jagrut BharatKumar Shukla

    Hi,
    This is not your requirment but u can try this :
    CREATE OR REPLACE DIRECTORY text_file AS 'D:\TEXT_FILE\';
    GRANT READ ON DIRECTORY text_file TO fah;
    GRANT WRITE ON DIRECTORY text_file TO fah;
    DROP TABLE load_a;
    CREATE TABLE load_a
    (a1 varchar2(20),
    a2 varchar2(200))
    ORGANIZATION EXTERNAL
    (TYPE ORACLE_LOADER
    DEFAULT DIRECTORY text_file
    ACCESS PARAMETERS
    (FIELDS TERMINATED BY ','
    LOCATION ('data.txt')
    select * from load_a;
    CREATE TABLE A AS select * from load_a;
    SELECT * FROM A
    Regards
    Faheem Latif

  • How to retrieve data from URL or querystring in bsp pages

    hi
    how to retrieve data from URL or querystring in bsp pages.
    thanks
    Edited by: Vijay Babu Dudla on Mar 23, 2009 7:35 AM

    Hello Friend,
    Vijay is correct.
    REQUEST is a system object available in runtime of BSP application.
    It is the object of interface IF_HTTP_REQUEST.
    Use methof REQUEST -> GET_FORM_DATA( )
    Regards
    Krishnendu

  • How to retrieve data from domain(Value Range)  of the table

    hi
    how to retrieve data from domain(Value Range)  of the table
    thanks

    Hello,
    You can try using the FM: DOMAIN_VALUE_GET TB_DOMAINVALUES_GET.
    BR,
    Suhas
    Edited by: Suhas Saha on Mar 24, 2009 10:08 AM

  • How to retrieve data from table(BOM_ITEM)

    Hi All,
    I wrote webservices using axis1.4 to get BOM information from SAP.. funtional module is CAD_DISPLAY_BOM_WITH_SUB_ITEMS
    webservices works fine..I'am able to retrieve data from Export Parameter..But not able to retrieve data from table
    How to retrieve data from table(BOM_ITEM)..?
    Cheers, all help would be greatly appreciated
    Vijay

    Hi,
    1. Create Page Process.
    2. Select Data Manipulation
    3. In category select "Automated Row Fetch"
    4. Specify process name, sequence, select "On Load - Before Header" in point.
    5. Specify owner, table, primary key, and the primary key column(Item name contains primary key).
    6. Create a process.
    7. In each item select "Database Column" in "Source Type".
    Regards,
    Kartik Patel
    http://patelkartik.blogspot.com/
    http://apex.oracle.com/pls/apex/f?p=9904351712:1

  • How to retrieve data from MDM using java API

    hi experts
    Please explain me the step by step procedure
    how to retrieve data from MDM using java API
    and please tell me what are the
    important classes and packages in MDM Java API
    thanks
    ramu

    Hi Ramchandra,
    You can refer to following links
    MDM Java API-pdf
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/2d18d355-0601-0010-fdbb-d8b143420f49
    webinr of java API
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/89243c32-0601-0010-559d-80d5b0884d67
    Following Fourm Threads will also help.
    Java API
    Java API
    Re: usage of  java API ,
    Matching Record
    Need Java API for Matching Record
    Thanks and Regards,
    Shruti.
    Edited by: Shruti Shah on Jul 16, 2008 12:35 PM

  • How to extract data From Hyperion Essbase to Flat Files

    Hi ,
    Can anyone tell me how to extract data from Hyperion essbase to Flat file(e.g. .csv , .txt ,...) or Oracle Table using ODI.
    Regards,
    Avneet

    Hi sutirtha,
    I have make one column as key column now i am getting this error,
    org.apache.bsf.BSFException: exception from Jython:
    Traceback (innermost last):
    File "<string>", line 1, in ?
    com.hyperion.odi.essbase.ODIEssbaseException: The number of columns returned by script [10] is less than the source data columns exposed [12]
    at com.hyperion.odi.essbase.ODIEssbaseDataReader.getAppData(Unknown Source)
    at com.hyperion.odi.essbase.AbstractEssbaseReader.extract(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java)
    at org.python.core.PyMethod.__call__(PyMethod.java)
    at org.python.core.PyObject.__call__(PyObject.java)
    at org.python.core.PyInstance.invoke(PyInstance.java)
    at org.python.pycode._pyx7.f$0(<string>:1)
    at org.python.pycode._pyx7.call_function(<string>)
    at org.python.core.PyTableCode.call(PyTableCode.java)
    at org.python.core.PyCode.call(PyCode.java)
    at org.python.core.Py.runCode(Py.java)
    at org.python.core.Py.exec(Py.java)
    at org.python.util.PythonInterpreter.exec(PythonInterpreter.java)
    at org.apache.bsf.engines.jython.JythonEngine.exec(JythonEngine.java:144)
    at com.sunopsis.dwg.codeinterpretor.k.a(k.java)
    at com.sunopsis.dwg.dbobj.SnpSessTaskSql.scripting(SnpSessTaskSql.java)
    at com.sunopsis.dwg.dbobj.SnpSessTaskSql.execScriptingOrders(SnpSessTaskSql.java)
    at com.sunopsis.dwg.dbobj.SnpSessTaskSql.execScriptingOrders(SnpSessTaskSql.java)
    at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTaskTrt(SnpSessTaskSql.java)
    at com.sunopsis.dwg.dbobj.SnpSessTaskSqlC.treatTaskTrt(SnpSessTaskSqlC.java)
    at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTask(SnpSessTaskSql.java)
    at com.sunopsis.dwg.dbobj.SnpSessStep.treatSessStep(SnpSessStep.java)
    at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java)
    at com.sunopsis.dwg.cmd.DwgCommandSession.treatCommand(DwgCommandSession.java)
    at com.sunopsis.dwg.cmd.DwgCommandBase.execute(DwgCommandBase.java)
    at com.sunopsis.dwg.cmd.e.k(e.java)
    at com.sunopsis.dwg.cmd.g.A(g.java)
    at com.sunopsis.dwg.cmd.e.run(e.java)
    at java.lang.Thread.run(Unknown Source)
    Caused by: com.hyperion.odi.essbase.ODIEssbaseException: The number of columns returned by script [10] is less than the source data columns exposed [12]
    at com.hyperion.odi.essbase.wrapper.EssbaseReportDataIterator.validateColumns(Unknown Source)
    at com.hyperion.odi.essbase.wrapper.EssbaseReportDataIterator.init(Unknown Source)
    ... 33 more
    com.hyperion.odi.essbase.ODIEssbaseException: com.hyperion.odi.essbase.ODIEssbaseException: The number of columns returned by script [10] is less than the source data columns exposed [12]
    at org.apache.bsf.engines.jython.JythonEngine.exec(JythonEngine.java:146)
    at com.sunopsis.dwg.codeinterpretor.k.a(k.java)
    at com.sunopsis.dwg.dbobj.SnpSessTaskSql.scripting(SnpSessTaskSql.java)
    at com.sunopsis.dwg.dbobj.SnpSessTaskSql.execScriptingOrders(SnpSessTaskSql.java)
    at com.sunopsis.dwg.dbobj.SnpSessTaskSql.execScriptingOrders(SnpSessTaskSql.java)
    at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTaskTrt(SnpSessTaskSql.java)
    at com.sunopsis.dwg.dbobj.SnpSessTaskSqlC.treatTaskTrt(SnpSessTaskSqlC.java)
    at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTask(SnpSessTaskSql.java)
    at com.sunopsis.dwg.dbobj.SnpSessStep.treatSessStep(SnpSessStep.java)
    at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java)
    at com.sunopsis.dwg.cmd.DwgCommandSession.treatCommand(DwgCommandSession.java)
    at com.sunopsis.dwg.cmd.DwgCommandBase.execute(DwgCommandBase.java)
    at com.sunopsis.dwg.cmd.e.k(e.java)
    at com.sunopsis.dwg.cmd.g.A(g.java)
    at com.sunopsis.dwg.cmd.e.run(e.java)
    at java.lang.Thread.run(Unknown Source)

  • How to download data from abap-ouput to excel sheet with logo

    how to download data from abap-ouput to excel sheet with standard logo
    Edited by: Harish Kasyap on Nov 18, 2008 8:19 AM
    Edited by: Harish Kasyap on Nov 18, 2008 8:20 AM

    For saving the report you can goto System -> List -> Save -> Local File -> Location where you want to save in your presentation server.
    You can also give a option in your selection screen to save the file to Presentation server using FM GUI_DOWNLOAD.
    Hope it helps.
    Thanks,
    Jayant.

  • Download read only excel file

    Hi Experts,
    How to download a READ ONLY excel file to workstation (local Machine).

    Hi kaleemullah,
    Steps to create a BDC program.
    1. Create an internal table with fields same as Excel sheet fields.
    2. Declare an internal table with BDCDATA table to store the BDC recording.
    3. Declare an internal table with BDCMSGCOL to store the error messages after
    the execution of the BDC.
    4. Write the code using the fun. module ALSM_EXCEL_TO_INTERNAL_TABLE
    to upload the data from the excel sheet.
    5. loop that internal table and write the Subroutines to fill the internal table
    BDCDATA with the recording of a specified Transaction Code.
    6. Using Call Transaction execute the BDC recording.
    7. Check Sy-subrc = 0 and store the error messages in the internal table.
    8. If you want you can pass those error records to a session using the SESSION method.
    Here is an example of a BDC program, but this program is from a text file. Change the function module WS_UPLOAD with ALSM_EXCEL_TO_INTERNAL_TABLE
    to upload an excel and write the program with your BDC recording. You can do recording using t-code SHDB.
    Sample Program:
    REPORT ZRAJ_DATASET_XD01 NO STANDARD PAGE HEADING LINE-SIZE 132
    LINE-COUNT 60
    MESSAGE-ID Z00.
    Table/Structure declarations. *
    TABLES : KNA1. "Customer master
    Constants declarations. *
    CONSTANTS : C_MODE VALUE 'N',
    C_UPDATE VALUE 'S',
    C_X VALUE 'X',
    C_SESS TYPE APQI-GROUPID VALUE 'ZCUSTOMER', "Session Name
    C_XD01 LIKE TSTC-TCODE VALUE 'XD01'.
    Variable declarations. *
    DATA : V_FNAME(15) VALUE SPACE, " Name of file to be created
    V_FAILREC TYPE I, " No of failed records
    V_MSG(255), " Message Text
    V_ERRREC TYPE I, " No of failed records
    V_LINES TYPE I. " No of records
    *-- FLAG DECLARATIONS
    DATA : FG_DATA_EXIST VALUE 'X', " Check for data
    FG_SESSION_OPEN VALUE ' '. " Check for Session Open
    Structures / Internal table declarations *
    *-- Structure to hold BDC data
    TYPES : BEGIN OF T_BDCTABLE.
    INCLUDE STRUCTURE BDCDATA.
    TYPES END OF T_BDCTABLE.
    *-- Structure to trap BDC messages
    TYPES : BEGIN OF T_MSG.
    INCLUDE STRUCTURE BDCMSGCOLL.
    TYPES : END OF T_MSG.
    *-- Structure to trap ERROR messages
    TYPES : BEGIN OF T_ERR_MSG,
    MESSAGE(255),
    END OF T_ERR_MSG.
    *--Internal table to store flat file data
    DATA:BEGIN OF IT_KNA1 OCCURS 0,
    KUNNR LIKE KNA1-KUNNR,
    KTOKD LIKE T077D-KTOKD,
    NAME1 LIKE KNA1-NAME1,
    SORTL LIKE KNA1-SORTL,
    ORT01 LIKE KNA1-ORT01,
    PSTLZ LIKE KNA1-PSTLZ,
    LAND1 LIKE KNA1-LAND1,
    SPRAS LIKE KNA1-SPRAS,
    LZONE LIKE KNA1-LZONE,
    END OF IT_KNA1.
    *-- Internal table to hold BDC data
    DATA: IT_BDCDATA TYPE STANDARD TABLE OF T_BDCTABLE WITH HEADER LINE,
    *-- Internal Table to store ALL messages
    IT_MSG TYPE STANDARD TABLE OF T_MSG WITH HEADER LINE,
    *-- Internal Table to store error messages
    IT_ERR_MSG TYPE STANDARD TABLE OF T_ERR_MSG WITH HEADER LINE.
    Selection Screen. *
    SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
    PARAMETERS : P_FLNAME(15) OBLIGATORY.
    SELECTION-SCREEN END OF BLOCK B1.
    SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-002.
    SELECTION-SCREEN BEGIN OF LINE.
    PARAMETERS : R_LIST RADIOBUTTON GROUP GRP1.
    SELECTION-SCREEN COMMENT 5(20) TEXT-003.
    PARAMETERS : R_SESS RADIOBUTTON GROUP GRP1.
    SELECTION-SCREEN COMMENT 30(20) TEXT-004.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN END OF BLOCK B2.
    Event:Initialization *
    INITIALIZATION.
    AT Selection Screen. *
    AT SELECTION-SCREEN.
    Event: Start-of-Selection *
    START-OF-SELECTION.
    V_FNAME = P_FLNAME.
    PERFORM GET_DATA.
    PERFORM GENERATE_DATASET.
    Event: End-of-Selection *
    END-OF-SELECTION.
    IF FG_DATA_EXIST = ' '.
    MESSAGE I010 WITH TEXT-009.
    EXIT.
    ENDIF.
    PERFORM GENERATE_BDCDATA.
    PERFORM DISPLAY_ERR_RECS.
    Event: top-of-page
    TOP-OF-PAGE.
    FORM DEFINITIONS *
    *& Form get_data
    Subroutine to get the data from mard
    --> p1 text
    <-- p2 text
    FORM GET_DATA.
    CALL FUNCTION 'UPLOAD'
    EXPORTING
    CODEPAGE = ' '
    FILENAME = 'C:\XD01.TXT'
    FILETYPE = 'DAT'
    ITEM = ' '
    FILEMASK_MASK = ' '
    FILEMASK_TEXT = ' '
    FILETYPE_NO_CHANGE = ' '
    FILEMASK_ALL = ' '
    FILETYPE_NO_SHOW = ' '
    LINE_EXIT = ' '
    USER_FORM = ' '
    USER_PROG = ' '
    SILENT = 'S'
    IMPORTING
    FILESIZE =
    CANCEL =
    ACT_FILENAME =
    ACT_FILETYPE =
    TABLES
    DATA_TAB = IT_KNA1
    EXCEPTIONS
    CONVERSION_ERROR = 1
    INVALID_TABLE_WIDTH = 2
    INVALID_TYPE = 3
    NO_BATCH = 4
    UNKNOWN_ERROR = 5
    GUI_REFUSE_FILETRANSFER = 6
    OTHERS = 7
    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 IT_KNA1[] IS INITIAL.
    FG_DATA_EXIST = ' '.
    ENDIF.
    ENDFORM. " get_data
    *& Form GENERATE_DATASET
    text
    --> p1 text
    <-- p2 text
    FORM GENERATE_DATASET.
    MESSAGE I010 WITH 'OPENING FILE IN APPLICATION SERVER'.
    **--Creating a data set in application server
    OPEN DATASET V_FNAME FOR OUTPUT IN TEXT MODE.
    **---Transfering data from internal table to dataset
    MESSAGE I010 WITH 'TRANSFERING DATA FROM INETERAL TABLE TO THE FILE'.
    LOOP AT IT_KNA1.
    TRANSFER IT_KNA1 TO V_FNAME.
    ENDLOOP.
    **--Closing the dataset
    MESSAGE I010 WITH 'CLOSING THE FILE'.
    CLOSE DATASET V_FNAME.
    ENDFORM. " GENERATE_DATASET
    *& Form BDC_DYNPRO
    text
    -->P_0467 text
    -->P_0468 text
    FORM BDC_DYNPRO USING PROGRAM DYNPRO.
    CLEAR IT_BDCDATA.
    IT_BDCDATA-PROGRAM = PROGRAM.
    IT_BDCDATA-DYNPRO = DYNPRO.
    IT_BDCDATA-DYNBEGIN = 'X'.
    APPEND IT_BDCDATA.
    ENDFORM.
    *& Form BDC_FIELD
    text
    -->P_0472 text
    -->P_0473 text
    FORM BDC_FIELD USING FNAM FVAL.
    IF NOT FVAL IS INITIAL.
    CLEAR IT_BDCDATA.
    IT_BDCDATA-FNAM = FNAM.
    IT_BDCDATA-FVAL = FVAL.
    APPEND IT_BDCDATA.
    ENDIF.
    ENDFORM.
    *& Form GENERATE_BDCDATA
    text
    --> p1 text
    <-- p2 text
    FORM GENERATE_BDCDATA.
    REFRESH IT_KNA1.
    Opening dataset for reading
    OPEN DATASET V_FNAME FOR INPUT IN TEXT MODE.
    Reading the file from application server
    DO.
    CLEAR: IT_KNA1,IT_BDCDATA.
    REFRESH IT_BDCDATA.
    READ DATASET V_FNAME INTO IT_KNA1.
    IF SY-SUBRC <> 0.
    EXIT.
    ELSE.
    Populate BDC Data for Initial Screen
    PERFORM : BDC_DYNPRO USING 'SAPMF02D' '0100',
    BDC_FIELD USING 'BDC_CURSOR' 'RF02D-KUNNR',
    BDC_FIELD USING 'BDC_OKCODE' '/00',
    BDC_FIELD USING 'RF02D-KUNNR' IT_KNA1-KUNNR,
    BDC_FIELD USING 'RF02D-KTOKD' IT_KNA1-KTOKD.
    Populate BDC Data for Second Screen
    PERFORM : BDC_DYNPRO USING 'SAPMF02D' '0110',
    BDC_FIELD USING 'BDC_CURSOR' 'KNA1-NAME1',
    BDC_FIELD USING 'BDC_OKCODE' '/00',
    BDC_FIELD USING 'KNA1-NAME1' IT_KNA1-NAME1,
    BDC_FIELD USING 'KNA1-SORTL' IT_KNA1-SORTL,
    BDC_FIELD USING 'KNA1-ORT01' IT_KNA1-ORT01,
    BDC_FIELD USING 'KNA1-PSTLZ' IT_KNA1-PSTLZ,
    BDC_FIELD USING 'KNA1-LAND1' IT_KNA1-LAND1,
    BDC_FIELD USING 'KNA1-SPRAS' IT_KNA1-SPRAS.
    Populate BDC Data for Third Screen
    PERFORM : BDC_DYNPRO USING 'SAPMF02D' '0120',
    BDC_FIELD USING 'BDC_CURSOR' 'KNA1-LZONE',
    BDC_FIELD USING 'BDC_OKCODE' '=UPDA',
    BDC_FIELD USING 'KNA1-LZONE' IT_KNA1-LZONE.
    CALL TRANSACTION C_XD01 USING IT_BDCDATA
    MODE C_MODE
    UPDATE C_UPDATE
    MESSAGES INTO IT_MSG.
    IF SY-SUBRC <> 0.
    *--In case of error list display
    IF R_LIST = C_X.
    V_ERRREC = V_ERRREC + 1.
    PERFORM FORMAT_MESSAGE.
    IT_ERR_MSG-MESSAGE = V_MSG.
    APPEND IT_ERR_MSG.
    CLEAR : V_MSG,IT_ERR_MSG.
    ENDIF.
    *--In case of session log
    IF R_SESS = C_X.
    *-- In case of transaction fails.
    IF FG_SESSION_OPEN = ' '.
    FG_SESSION_OPEN = C_X.
    PERFORM BDC_OPEN_GROUP.
    ENDIF. " IF FG_SESSION_OPEN = ' '.
    *-- Insert BDC Data..
    PERFORM BDC_INSERT_DATA.
    ENDIF. " IF R_SESS = C_X.
    ENDIF. " IF SY-SUBRC <> 0.
    ENDIF. " IF SY-SUBRC <> 0.
    ENDDO.
    Closing the dataset
    CLOSE DATASET V_FNAME.
    *-- Close the session if opened
    IF FG_SESSION_OPEN = C_X.
    PERFORM BDC_CLOSE_GROUP.
    CALL TRANSACTION 'SM35'.
    ENDIF.
    ENDFORM. " GENERATE_BDCDATA
    *& Form BDC_OPEN_GROUP
    text
    --> p1 text
    <-- p2 text
    FORM BDC_OPEN_GROUP.
    CALL FUNCTION 'BDC_OPEN_GROUP'
    EXPORTING
    CLIENT = SY-MANDT
    DEST = FILLER8
    GROUP = C_SESS
    HOLDDATE = FILLER8
    KEEP = C_X
    USER = SY-UNAME
    RECORD = FILLER1
    IMPORTING
    QID =
    EXCEPTIONS
    CLIENT_INVALID = 1
    DESTINATION_INVALID = 2
    GROUP_INVALID = 3
    GROUP_IS_LOCKED = 4
    HOLDDATE_INVALID = 5
    INTERNAL_ERROR = 6
    QUEUE_ERROR = 7
    RUNNING = 8
    SYSTEM_LOCK_ERROR = 9
    USER_INVALID = 10
    OTHERS = 11
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    ENDFORM. " BDC_OPEN_GROUP
    *& Form BDC_INSERT_DATA
    text
    --> p1 text
    <-- p2 text
    FORM BDC_INSERT_DATA.
    CALL FUNCTION 'BDC_INSERT'
    EXPORTING
    TCODE = C_XD01
    POST_LOCAL = NOVBLOCAL
    PRINTING = NOPRINT
    TABLES
    DYNPROTAB = IT_BDCDATA
    EXCEPTIONS
    INTERNAL_ERROR = 1
    NOT_OPEN = 2
    QUEUE_ERROR = 3
    TCODE_INVALID = 4
    PRINTING_INVALID = 5
    POSTING_INVALID = 6
    OTHERS = 7
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    ENDFORM. " BDC_INSERT_DATA
    *& Form BDC_CLOSE_GROUP
    text
    --> p1 text
    <-- p2 text
    FORM BDC_CLOSE_GROUP.
    CALL FUNCTION 'BDC_CLOSE_GROUP'
    EXCEPTIONS
    NOT_OPEN = 1
    QUEUE_ERROR = 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.
    ENDFORM. " BDC_CLOSE_GROUP
    *& Form FORMAT_MESSAGE
    text
    --> p1 text
    <-- p2 text
    FORM FORMAT_MESSAGE.
    CLEAR V_LINES.
    DESCRIBE TABLE IT_MSG LINES V_LINES.
    READ TABLE IT_MSG INDEX V_LINES.
    CLEAR V_MSG.
    CALL FUNCTION 'FORMAT_MESSAGE'
    EXPORTING
    ID = IT_MSG-MSGID
    LANG = IT_MSG-MSGSPRA
    NO = IT_MSG-MSGNR
    V1 = IT_MSG-MSGV1
    V2 = IT_MSG-MSGV2
    V3 = IT_MSG-MSGV3
    V4 = IT_MSG-MSGV4
    IMPORTING
    MSG = V_MSG
    EXCEPTIONS
    NOT_FOUND = 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.
    ENDFORM. " FORMAT_MESSAGE
    *& Form DISPLAY_ERR_RECS
    text
    --> p1 text
    <-- p2 text
    FORM DISPLAY_ERR_RECS.
    LOOP AT IT_ERR_MSG.
    WRITE: / IT_ERR_MSG-MESSAGE.
    ENDLOOP.
    ENDFORM. " DISPLAY_ERR_RECS
    Hope this resolves your query.
    Reward all the helpful answers.
    Regards

  • Upload data from multiple worksheets of excel file into SAP by using MIME?

    Hi all,
    I'm trying to getting the data from a multiple worksheet excel file by usin the MIME Repository.
    First of all i realizied it like [here|http://abap-explorer.blogspot.com/2008/12/upload-data-from-multiple-worksheets-of.html] in a normal ABAP Report.
    By trying to transfer the code to a WebDynpro Component, i get problems.
    With this part of code, because ActiveX is not allowed in our Webbrowser. So i have to find another solution to get the data from the excel file.
    CALL METHOD c_oi_container_control_creator=>get_container_control
    IMPORTING
    control = iref_control
    error   = iref_error
    I tried to rebuild this solution in webdynpro. But it dont works.
    So my next step was trying to Read the Excel sheet directly from MIME by getting the Content (XString).
    But there is no useful information Just a mix out of '######' and other symbols.
    By converting it into String the same problem.
    Maybe someone has an idea how to rebuild [this code|http://abap-explorer.blogspot.com/2008/12/upload-data-from-multiple-worksheets-of.html] in Webdynpro that it works correctly.
    Currently Im Using the Fileupload UI Element. All Works fine. I can Upload the Excel file to MIME Repository and i can open it from there.
    But i cant get the same clear informationen from the file, to write it later in a Database, like before without webdynpro.
    i hope someone can help me.
    Edited by: Sascha Baumann on Apr 20, 2009 4:28 PM

    You can't read the native binary Excel Format in server side ABAP.  The functions and classes that did this in Classic Dynpro used OLE Automation via the SAPGUI Control Framework to remotely control Excel to read the data.  Because in the browser you have no connection to the SAPGUI or are sandboxed inside the browser; the same functionality is not possible. 
    I would suggest that you look into saving the Excel file as a open, text format.  You might be able to use XML (although the Excel XML format can be complex) to support multiple sheets. You would have to build the logic yourself (using XSLT or the iXML parser) to process the XML format back into ABAP data.

  • How to retrieve data from virtual infotype?

    Hi.
    I'm trying to write an ABAP program that's retrieving data from infotype 2501.
    If i'm looking at this table PA2501 from SE16, i can see that it's empty, but...
    I have an HR program that's using the PNP and i can see in debbuging mode allot of data over there.
    So, my question is: how can i get this data with a simple SELECT command? where is the data?
    Thanks!
    Barak.

    There may be no data physically stored in table PA2501, it may reside in other tables but programatically pulled by the infotype into internal tables. Surender has given a good example, there are many more examples like some fields are stored in another table. Like for infotype 105, some fields are stored in PA0105 and some are stored in PA0106 which are pulled and displayed on one infotype screen i.e. 105 and hence we do not have a screen for 106. It may be same situation.
    If you have to have a SELECT access, then only way is to debug the code and see how it is pulling the data, which tables etc.

Maybe you are looking for

  • Help in regarding alert log error...referring to standby

    Database: Single Instance, 10.2.0.3 OS: Redhat Linux 5 I checkd on my standby if logs are applied or not by the following command. SQL> SELECT SEQUENCE#,APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#; The result is "YES" for all corresponding logs. B

  • Getting ext. DVD to play

    The CD/DVD drive in this machine died and so in haste I replaced it with a HPDVD1040 external drive. My mac sees the drive. Will play and burn cd's, but when I try to play a dvd it gives me an error code of -70012 and comment that a valid dvd drive c

  • Firefox hangs when trying to open youtube videos

    hi, everytime I access youtube, and after starting to play a video, firefox hangs and ans stop working and I need to open task manager to close the process. I tried also with internet explorer and I happens the same but I get a script error, but with

  • FMV's, or something of the sort

    Is it possible to mix Java2D and Java3D in the same application? i want to make a movie sequence for a game and i figured id just do something in Java3D, but if there are other suggestions out there, i'd be glad to hear it. thanks for all your help.

  • Converting String to int again...

    telno.addActionListener(this); public void actionPerformed(ActionEvent e){ int x, p, y; if(e.getSource()==telno){ x = Integer.parceInt(telno.getText());      p = x/10000;           y = x%10000; there's an error 'cannot resolve symbol' when I try to c