Looking for example to export data from a DynPro table to Excel file

Hello,
I have a certain content in a table.
I would like to export this content to Excel file and let the user save it on his PC. I tried to use the Office Controller but with no success.
Have someone already made something like this and can show me an example?

Hi
I already explained this in another post. Anyway i will cut and paste the same for you.Here you go.Sample way to create a Excel file and then download it to a local pc using a FileUI Download element.
We are developing a generic component for the same requirement which will download data to a excel from any table.
Anyway here is something which will give you some kind of idea as to how you can write the data from WebDynpro to a excel file.
For running this application
Ensure that the requisite JAR files are set for the Excel API's. See the blog link below.
Steps :
All your files in the machine running the WAS will be created in the default location
Alias : webdynpro/resources
Path : <Drive>:/usr/sap/J2E/JC00/j2ee/cluster/server0/temp/webdynpro/web
You can open your Visual Administrator and go to HTTP provider service and then create your own Alias. say
Alias : myAlias
Path : <Drive>:/mydirectory/myfiles
Once this is done restart your WebAS.
The code explained will perform the following.
There is a button UI element and a Download UI element. On click of the Action associated with the button ui element
The code below will create a excel file in the location mentioned.
On click of the download UI element you can view the excel file that was created.
Now create a New project in your NWDS
Follow the blog for importing the necessary jar files for Excel
/people/perumal.kanthan/blog/2005/03/21/reading-excel-data-from-java-using-hssf-api
Once that is done you can create say a button in your Webdynpro and associate it with a action.
Then you can write some code like the one below.
//Declare this in the end between the Begin others block.
  private FileOutputStream out = null;
  private HSSFWorkbook workBook = null;
  private HSSFSheet hsSheet = null;
  private HSSFRow row = null;
  private HSSFCell cell = null;
  private HSSFCellStyle cs = null;
  private HSSFCellStyle cs1 = null;
  private HSSFCellStyle cs2 = null;
  private HSSFDataFormat dataFormat = null;
  private HSSFFont f = null;
  private HSSFFont f1 = null;
//Code to create the Excel.
  public void onActionExportToExcel(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
    //@@begin onActionExportToExcel(ServerEvent)
    try
      out = new FileOutputStream("C:/mydirectory/myfiles/testexcel.xls");
      workBook = new HSSFWorkbook();
      hsSheet = workBook.createSheet("My Sheet");
      cs = workBook.createCellStyle();
      cs1 = workBook.createCellStyle();
      cs2 = workBook.createCellStyle();
      dataFormat = workBook.createDataFormat();
      f =  workBook.createFont();
      f1 = workBook.createFont();
       f.setFontHeightInPoints((short) 12);
//          make it blue
       f.setColor( (short)HSSFFont.COLOR_NORMAL );
//           make it bold
//          arial is the default font
       f.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
//          set font 2 to 10 point type
       f1.setFontHeightInPoints((short) 10);
//          make it red
       f1.setColor( (short)HSSFFont.COLOR_RED );
//          make it bold
       f1.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
      f1.setStrikeout(true);
      cs.setFont(f);
      cs.setDataFormat(dataFormat.getFormat("#,##0.0"));
//       set a thick border
     cs2.setBorderBottom(cs2.BORDER_THICK);
//       fill w fg fill color
     cs2.setFillPattern((short) HSSFCellStyle.SOLID_FOREGROUND);
    cs2.setFillBackgroundColor((short)HSSFCellStyle.SOLID_FOREGROUND);
//       set the cell format to text see HSSFDataFormat for a full list
     cs2.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));
     cs2.setFont(f1);
     cs2.setLocked(true);
     cs2.setWrapText(true);
     row = hsSheet.createRow(0);
     hsSheet.createFreezePane(0,1,1,1);
    for(int i=1; i<10;i++)
       cell = row.createCell((short)i);
      cell.setCellValue("Excel Column "+i);
      cell.setCellStyle(cs2);
     workBook.write(out);
     out.close();
//Read the file that was created.
     FileInputStream fin = new FileInputStream("C:/mydirectory/myfiles/testexcel.xls");
     byte b[] = new byte[fin.available()];
     fin.read(b,0,b.length);
     fin.close();
     wdContext.currentContextElement().setDataContent(b);
    catch(Exception e)
      wdComponentAPI.getComponent().getMessageManager().reportException("Exception while reading file "+e,true);  
    //@@end
You can now add a Download UI Element to the layout.
Create a Context Attribute say "dataContent" and this should be of Type Binary.
The Data property of the File UI download element should be mapped to dataContent.
In the init method write code like
This is done for the download element.
     IWDAttributeInfo attInfo = wdContext.getNodeInfo().getAttribute("dataContent");   
     IWDModifiableBinaryType binaryType = (IWDModifiableBinaryType) attInfo.getModifiableSimpleType();
//In addition the FileDownload UI element needs for defined resource types  
     binaryType.setFileName("testexcel.xls");
     binaryType.setMimeType(WDWebResourceType.XLS);
Hope that helps you. Anyway its a sample and it should be helpful for you to see how you can modify it and of course maintain some standards in coding unlike the test sample given above :).
Let me know if you require further clarifications
regards
ravi

Similar Messages

  • How to export data from a Dynpro table to Excel file?

    Hi
    Here I go again. I read the post <b>Looking for example to export data from a DynPro table to Excel file</b> and put the code lines into a Web Dynpro Project where we need to export a dynpro table to Excel file but exactly at line 23 it doesn't recognize <b>workBook = new HSSFWorkbook();</b>
    1     //Declare this in the end between the Begin others block.
    2     
    3     private FileOutputStream out = null;
    4     private HSSFWorkbook workBook = null;
    5     private HSSFSheet hsSheet = null;
    6     private HSSFRow row = null;
    7     private HSSFCell cell = null;
    8     private HSSFCellStyle cs = null;
    9     private HSSFCellStyle cs1 = null;
    10     private HSSFCellStyle cs2 = null;
    11     private HSSFDataFormat dataFormat = null;
    12     private HSSFFont f = null;
    13     private HSSFFont f1 = null;
    14     
    15     //Code to create the Excel.
    16     
    17     public void onActionExportToExcel(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
    18     {
    19     //@@begin onActionExportToExcel(ServerEvent)
    20     try
    21     {
    22     out = new FileOutputStream("C:/mydirectory/myfiles/testexcel.xls");
    23     workBook = new HSSFWorkbook();
    24     hsSheet = workBook.createSheet("My Sheet");
    25     cs = workBook.createCellStyle();
    26     cs1 = workBook.createCellStyle();
    27     cs2 = workBook.createCellStyle();
    28     dataFormat = workBook.createDataFormat();
    29     f = workBook.createFont();
    30     f1 = workBook.createFont();
    31     f.setFontHeightInPoints((short) 12);
    32     // make it blue
    33     f.setColor( (short)HSSFFont.COLOR_NORMAL );
    34     // make it bold
    35     // arial is the default font
    36     f.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    37     
    38     // set font 2 to 10 point type
    39     f1.setFontHeightInPoints((short) 10);
    40     // make it red
    41     f1.setColor( (short)HSSFFont.COLOR_RED );
    42     // make it bold
    43     f1.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    44     f1.setStrikeout(true);
    45     cs.setFont(f);
    46     cs.setDataFormat(dataFormat.getFormat("#,##0.0"));
    47     
    48     // set a thick border
    49     cs2.setBorderBottom(cs2.BORDER_THICK);
    50     
    51     // fill w fg fill color
    52     cs2.setFillPattern((short) HSSFCellStyle.SOLID_FOREGROUND);
    53     cs2.setFillBackgroundColor((short)HSSFCellStyle.SOLID_FOREGROUND);
    54     // set the cell format to text see HSSFDataFormat for a full list
    55     cs2.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));
    56     cs2.setFont(f1);
    57     cs2.setLocked(true);
    58     cs2.setWrapText(true);
    59     row = hsSheet.createRow(0);
    60     hsSheet.createFreezePane(0,1,1,1);
    61     for(int i=1; i<10;i++)
    62     {
    63     cell = row.createCell((short)i);
    64     cell.setCellValue("Excel Column "+i);
    65     cell.setCellStyle(cs2);
    66     }
    67     workBook.write(out);
    68     out.close();
    69     
    70     //Read the file that was created.
    71     
    72     FileInputStream fin = new FileInputStream("C:/mydirectory/myfiles/testexcel.xls");
    73     byte b[] = new byte[fin.available()];
    74     fin.read(b,0,b.length);
    75     fin.close();
    76     
    77     wdContext.currentContextElement().setDataContent(b);
    78     }
    79     catch(Exception e)
    80     {
    81     wdComponentAPI.getComponent().getMessageManager().reportException("Exception while reading file "+e,true);
    82     }
    83     //@@end
    84     }
    I don't know why this happen? Any information I will appreciate it.
    Thanks in advance!!!
    Tokio Franco Chang

    After test the code lines appears this error stacktrace:
    [code]
    java.lang.NoClassDefFoundError: org/apache/poi/hssf/usermodel/HSSFWorkbook
         at com.sap.tc.webdynpro.progmodel.api.iwdcustomevent.ExportToExcel.onActionAct1(ExportToExcel.java:232)
         at com.sap.tc.webdynpro.progmodel.api.iwdcustomevent.wdp.InternalExportToExcel.wdInvokeEventHandler(InternalExportToExcel.java:147)
         at com.sap.tc.webdynpro.progmodel.generation.DelegatingView.invokeEventHandler(DelegatingView.java:87)
         at com.sap.tc.webdynpro.progmodel.controller.Action.fire(Action.java:67)
         at com.sap.tc.webdynpro.clientserver.task.WebDynproMainTask.handleAction(WebDynproMainTask.java:101)
         at com.sap.tc.webdynpro.clientserver.task.WebDynproMainTask.handleActionEvent(WebDynproMainTask.java:304)
         at com.sap.tc.webdynpro.clientserver.task.WebDynproMainTask.execute(WebDynproMainTask.java:649)
         at com.sap.tc.webdynpro.clientserver.cal.AbstractClient.executeTasks(AbstractClient.java:59)
         at com.sap.tc.webdynpro.clientserver.cal.ClientManager.doProcessing(ClientManager.java:252)
         at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doWebDynproProcessing(DispatcherServlet.java:154)
         at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doContent(DispatcherServlet.java:116)
         at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doPost(DispatcherServlet.java:55)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:392)
         at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:266)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:345)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:323)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:865)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:240)
         at com.sap.engine.services.httpserver.server.Client.handle(Client.java:92)
         at com.sap.engine.services.httpserver.server.Processor.request(Processor.java:148)
         at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:37)
         at com.sap.engine.core.cluster.impl6.session.UnorderedChannel$MessageRunner.run(UnorderedChannel.java:71)
         at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
         at java.security.AccessController.doPrivileged(Native Method)
         at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:95)
         at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:159)
    Thanks in advance!!!
    Tokio Franco Chang
    [/code]

  • Exporting data from Oracle to an existing Excel file

    Hi,
    I want to know if it is possible to open up an excel file on the server (with the necessary lay-out) and to write the query results in it?
    Another remark: the file needs to be saved under a different name (we use the user name as part of the files since the file will be sent through email rather than be displayed on the user's screen)

    If you are satisfied with a straight dump, you might want to use utl_file to make a standard CSV-file.
    If you need a little more control of the layout, you might want to check out the SYLK file format (quite ancient)
    These require no Excel application and works on UNIX servers too. If you really have to have the full magic (on a Win32 platform) you could try using Jacob or some other Java-COM-bridge to launch the Excel-application and enter the values into the worksheet but this falls into the "duct tape and chewing gum"-category of stability in my opinion...

  • PROBLEM IN EXPORTING DATA FROM A RELATIONAL TABLE TO ANOTHER RELATIONAL TAB

    Hi,
    While trying to export data from a source table to a target table, problem occurs with loading the data in the work table(SrcSet0)[As shown in the operator]. The Work Table has been dropped and created successfully, the problem is coming with loading the data( in this work table(SrcSet0)). The error details as mentioned below. Please advise:-
    ODI-1227: Task SrcSet0 (Loading) fails on the source ORACLE connection ORACLE_SOURCE.
    Caused By: java.sql.SQLException: SQL string is not Query
         at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1442)
         at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3752)
         at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3806)
         at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1667)
         at oracle.odi.query.JDBCTemplate.executeQuery(JDBCTemplate.java:189)
         at oracle.odi.runtime.agent.execution.sql.SQLDataProvider.readData(SQLDataProvider.java:89)
         at oracle.odi.runtime.agent.execution.sql.SQLDataProvider.readData(SQLDataProvider.java:1)
         at oracle.odi.runtime.agent.execution.DataMovementTaskExecutionHandler.handleTask(DataMovementTaskExecutionHandler.java:67)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.processTask(SnpSessTaskSql.java:2906)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTask(SnpSessTaskSql.java:2609)
         at com.sunopsis.dwg.dbobj.SnpSessStep.treatAttachedTasks(SnpSessStep.java:537)
         at com.sunopsis.dwg.dbobj.SnpSessStep.treatSessStep(SnpSessStep.java:453)
         at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java:1740)
         at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor$2.doAction(StartSessRequestProcessor.java:338)
         at oracle.odi.core.persistence.dwgobject.DwgObjectTemplate.execute(DwgObjectTemplate.java:214)
         at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor.doProcessStartSessTask(StartSessRequestProcessor.java:272)
         at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor.access$0(StartSessRequestProcessor.java:263)
         at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor$StartSessTask.doExecute(StartSessRequestProcessor.java:822)
         at oracle.odi.runtime.agent.processor.task.AgentTask.execute(AgentTask.java:123)
         at oracle.odi.runtime.agent.support.DefaultAgentTaskExecutor$2.run(DefaultAgentTaskExecutor.java:82)
         at java.lang.Thread.run(Thread.java:662)
    Thanks
    Anindya

    Hi actdi,
    This is my KM_IKM SQL Incremental Update.xml code:-
    and I have find it(for (int i=odiRef.getDataSetMin(); i <= odiRef.getDataSetMax(); i++)) and high lighted it(Bold Text).
    So, please advise.
    Here is the main part of this code because the code is too long to post.It exceeds maxlength for the msg.
    So here it is:
    <Object class="com.sunopsis.dwg.dbobj.SnpTxtHeader">
    <Field name="Enc" type="java.lang.String">null</Field>
    <Field name="EncKey" type="java.lang.String">null</Field>
    <Field name="ITxt" type="com.sunopsis.sql.DbInt"><![CDATA[1695003]]></Field>
    <Field name="ITxtOrig" type="com.sunopsis.sql.DbInt"><![CDATA[102]]></Field>
    <Field name="SqlIndGrp" type="java.lang.String"><![CDATA[2]]></Field>
    <Field name="Txt" type="java.lang.String"><![CDATA[insert into <%=odiRef.getTable("L","INT_NAME","A")%>
    <%=odiRef.getColList("", "[COL_NAME]", ",\n\t", "", "(((INS or UPD) and !TRG) and REW)")%>,
    IND_UPDATE
    *<%for (int i=odiRef.getDataSetMin(); i <= odiRef.getDataSetMax(); i++){%>*
    <%=odiRef.getDataSet(i, "Operator")%>
    select <%=odiRef.getPop("DISTINCT_ROWS")%>
    <%=odiRef.getColList(i,"", "[EXPRESSION]", ",\n\t", "", "(((INS or UPD) and !TRG) and REW)")%>,
    <% if (odiRef.getDataSet(i, "HAS_JRN").equals("1")) { %>
    JRN_FLAG IND_UPDATE
    <%} else {%>
    'I' IND_UPDATE
    <%}%>
    from <%=odiRef.getFrom(i)%>
    where (1=1)
    <%=odiRef.getJoin(i)%>
    <%=odiRef.getFilter(i)%>
    <%=odiRef.getJrnFilter(i)%>
    <%=odiRef.getGrpBy(i)%>
    <%=odiRef.getHaving(i)%>
    <%}%>
    ]]></Field>
    </Object>
    <Object class="com.sunopsis.dwg.dbobj.SnpLineTrt">
    <Field name="AlwaysExe" type="java.lang.String"><![CDATA[0]]></Field>

  • Problem while exporting the data from a report to an excel file.

    Hi SAP guru's,
    I have a problem while exporting the data from a report to an excel file.
    The problem is that after exporting, the excel file seems to have some irrelevant characters....I am checking this using SOST transaction..
    Required text (Russian):
    Операции по счету                                    
    № документа     Тип документа     № учетной записи     Дата документа     Валюта     Сумма, вкл. НДС     Срок оплаты     Описание документа
    Current Text :
       ? 5 @ 0 F 8 8  ? >  A G 5 B C                                   
    !   4 > : C       "" 8 ?  4 > : C      !   C G 5 B = > 9  7 0 ? 8 A 8        0 B 0  4 > : C         0 ; N B 0      ! C <       ! @ > :  > ? ; 0 B K        ? 8 A 0 = 8 5  4 > : C
    Can you help me making configuration settings if any?
    Regards,
    Avinash Raju

    Hi Avinash
    To download  such characteres you need to adjust code page to be used during export. You can review SAP note 73606 to identify which code page is required for this language
    Best regards

  • How to export data from a Oracle table to a delimited file?

    I know how to load delimited file into a table, but how to export
    data from a Oracle table to a delimited file?
    Thanks in advance.

    Try looking at this link, it's long but there's three different solutions discussed in it. If you look at Barbara Boehmer's
    solution in her posts in the link below you'll see that she's addressed your concerns with spool files.
    Re: utl_smtp and triggers

  • Import/export data from ms sql 7 to xml file in a particular xpdl format

    I'm trying to write java program to import/export data from ms sql 7 to xml file in a particular xpdl format. Can anyone suggest how to do it?

    take a glance at what these guys do: http://www.openbusinessengine.org/docs/guide.html

  • Leading Zeros Missing - When exporting data from ALV grid display to Excel

    Hi,
    Am exporting the data from ALV GRID DISPLAY to Excel sheet using standard toolbar icon 'Local file'
    the leading zeros displayed in the ALV output is missing in the EXCEL sheet.
    (eg)  in ALV o/p - 0029. 
            in Excel - Only 29 is appearing.
    As per the requiement i have to show the leading zeros in excel also.
    Pls help on this issue.
    Thanks in advance..

    Hi ,
      Please set the property  :
      wa_fieldcat-lzero = 'X' .
    when you are creating field catalog for display alv data .
    your prob will solved .
    Regards ,
    Nilesh Jain

  • Export data from SAP Document Management System to File System(FileStore)

    Hi,
    We need to extract/ export data (documents and metadata) from SAP Document Management System to windows File System (File Store), can anyone suggest us tool or methodology to do the same.
    Thanks,
    Nilesh

    I'm also looking for a solution for this problem. We are capturing comments in BW-BPS layouts. They get stored in BW's document management system and we would like to export them out of the system for external reporting into an ACCESS database.

  • Exporting data from a jsp to a text file...

    Hi all.
    I have a jsp which displays a set of results in a tablular form....my clients now want me to include a button in this jsp page on clicking which i will be abl�e to export the entire data from the displayed page to a text file
    can anyone suggest me as to how to go about it...
    thanks

    Server side code(lets say servlet named exportServlet) behind the button can retreive the data in the same fashion as done for displaying on the JSP.
    But then, exportServlet writes data back on the HTTP response using the mime type application/octet-stream.
    See Javadoc for javax.servlet.ServletResponse.setContentType()

  • How to export data from a string to a CSV file

    Hello,
    i do have a string in a Livecycle Designer script object with a couple of rows with different entries divided by a semicolon:
    COLUMN1;COLUMN2;COLUMN3
    Entry1;Entry2;Entry3
    Entry4;Entry5;Entry6
    The goal is now to export this string from Livecycle Designer into a CSV file by clicking a button. Is there any solution suggested?
    Thank you very much.

    Hi,
    You can try creating a dataObject and then exporting it, you might get some warning messages popup but try this;
    var csvData = "COLUMN1;COLUMN2;COLUMN3\r\n";
    csvData += "Entry1;Entry2;Entry3\r\n";
    csvData += "Entry4;Entry5;Entry6\r\n";
    var pdf = event.target;
    pdf.createDataObject("Data.csv", csvData);
    pdf.exportDataObject({cName: "Data.csv"});
    If you replace the last line with
    pdf.exportDataObject({cName: "Data.csv", nLaunch: 2});
    It will open in whatever .csv is registered for (Excel on my system)
    Regards
    Bruce

  • Import data from oracle database table into csv file

    Hi
    I have to import data from a table into a csv file. Could anyone suggest the best method to do it? My application is JSP as frontend and have put business logic in servlet.
    Thanks in advance.

    FastReader from wisdomforce will help you quickly export data into csv file. http://www.wisdomforce.com
    fastreader can be called and executed as an external process ( Runtime.exec(..) ) to extract data from Oracle tables into flat file

  • How do I read a range of data from an open and "live" Excel file using LV7.0 Express

    I need to interface with software which continuously (once per second) writes a new array to a fixed location in an open Excel file. I would like to read this data into Labview from where I can do what I like with it. I am relatively new to LabView and have tried all "Read Data" examples that come with the product, Active examples seem very unclear. Anyone got any samples/suggestions to get me started?
    Attachments:
    Changing_Excel_file.xls ‏17 KB

    It is possible but might be a little bit complicated. Does your application opens the Excel file or Excel file was opened through Excel or another application already?
    In the first senario, once the excel is opened, start reading the data, do not close the report file (dispose the report) or close the excel file
    In the second senario, it is a little bit more complicated. You need to use low level Excel ActiveX functions. The procedure is:
    1. Open reference to Excel
    2. Activate the desired workbook if it is already opened
    or open a new file
    3. Activate the sheet containing the data
    4. Read the data
    5. Loop if necessary (step 2 if diff wb, step 3 if diff sht, 4 if same sheet)
    6. Close Excel reference (Very important, close the
    ref only, do not use Application.Exit to exit Excel).
    Hope this helps,
    -Joe

  • CALL RFC DATA FROM TWO LINKED TABLES IN EXCEL VBA

    Hi,
    I am using Excel VBA to call information from tables in SAP.
    This is working correctly, however I now need to be able to call information from another table where the two tables are linked by a common data field.
    Example.
    The first table I have lists all items in stock and contains an article number. The second table contains all article numbers and their descriptions.
    I want to be able to call the first table but to have the article codes description on there aswell.
    Here is the code I am currently using.
    Sub GetTable()
    'Connect to SAP
    Dim sapConn As Object 'Declare variant
    Set sapConn = CreateObject("SAP.Functions") 'Create ActiveX object
    sapConn.Connection.System = "QA2"
    sapConn.Connection.client = "900"
    sapConn.Connection.user = "mbrough"
    sapConn.Connection.Password = "st34lh"
    sapConn.Connection.Language = "EN"
    If sapConn.Connection.Logon(1, False) <> True Then 'Try Logon
       MsgBox "Cannot Log on to SAP"
    End If
    'Define the table specifics
    Dim objRfcFunc As Object
    Set objRfcFunc = sapConn.Add("RFC_READ_TABLE")
    Dim objQueryTab, objRowCount As Object
    Set objQueryTab = objRfcFunc.Exports("QUERY_TABLE")
    objQueryTab.Value = "LQUA"
    Set objRowCount = objRfcFunc.Exports("ROWCOUNT")
    objRowCount.Value = "15000"
    Dim objOptTab, objFldTab, objDatTab As Object
    Set objOptTab = objRfcFunc.Tables("OPTIONS")
    Set objFldTab = objRfcFunc.Tables("FIELDS")
    Set objDatTab = objRfcFunc.Tables("DATA")
    'Set the condition and refresh the table
    objOptTab.FreeTable
    objOptTab.Rows.Add
    objOptTab(objOptTab.RowCount, "TEXT") = "LGTYP BETWEEN 'K01' AND 'K06'"
    'Set fields to obtain and refresh table
    objFldTab.FreeTable
    'Then set values to call
    objFldTab.Rows.Add
    objFldTab(objFldTab.RowCount, "FIELDNAME") = "LGNUM"
    objFldTab.Rows.Add
    objFldTab(objFldTab.RowCount, "FIELDNAME") = "MATNR"
    objFldTab.Rows.Add
    objFldTab(objFldTab.RowCount, "FIELDNAME") = "WERKS"
    objFldTab.Rows.Add
    objFldTab(objFldTab.RowCount, "FIELDNAME") = "LGTYP"
    objFldTab.Rows.Add
    objFldTab(objFldTab.RowCount, "FIELDNAME") = "LGPLA"
    objFldTab.Rows.Add
    objFldTab(objFldTab.RowCount, "FIELDNAME") = "GESME"
    objFldTab.Rows.Add
    objFldTab(objFldTab.RowCount, "FIELDNAME") = "VERME"
    objFldTab.Rows.Add
    objFldTab(objFldTab.RowCount, "FIELDNAME") = "MEINS"
    If objRfcFunc.Call = False Then
       MsgBox objRfcFunc.Exception
    End If
    Dim objDatRec As Object
    Dim objFldRec As Object
    For Each objDatRec In objDatTab.Rows
       For Each objFldRec In objFldTab.Rows
          Cells(objDatRec.Index, objFldRec.Index) = _
                Mid(objDatRec("WA"), objFldRec("OFFSET") + 1, objFldRec("LENGTH"))
       Next
    Next
    End Sub
    The table which contains the article descriptions is called 'MAKT' and this table also contains the column 'MATNR' which is the article field.
    Many thanks,
    Mike

    Is there no way of connecting the tables within the code.
    IT won't give me access to SE11
    Thanks,
    Mike

  • Function module to save the data from ALV list to MS Excel file

    Hi,
    I am displaying an ALV list.
    I am assigning a pushbutton in the GUI status to save the list as a MS Excel file.
    Can you please let me know the function module to achieve this task.
    I tried 'SAP_CONVERT_TO_XLS_FORMAT'  FM but it is giving some type confict error.
    Thanks & Regards,
    Balaji.R

    ALV has this option built in, you may also find FM like [ALV_XXL_CALL|https://www.sdn.sap.com/irj/scn/advancedsearch?cat=sdn_all&query=alv_xxl_call&adv=false&sortby=cm_rnd_rankvalue].
    Can you elaborate a little more on your need, why adding an option that already exits?
    Regards

Maybe you are looking for

  • Not Printing the Content of Object:SOme Garbage Value on Screen

    i have made one program of Vehicle class which adds and prints the Details of Vehicles in the ArrayList but it always showa the Garbage Value in return. import java.util.*; import java.awt.*; import java.lang.*; import java.io.*; public class Vehicle

  • Photos fading

     Photos fading altho I'm using genuine HP ink on HP Advanced photo paper on my HP Photosmart 3210 AIO.  I thought this combination was to produce at least "near archive" quality that would last more than a year or two. By comparison I have photos pri

  • Can I deploy a certificate automatically in a new install of Firefox?

    I've looked at numerous posts regarding importing certificates into Firefox...none of which seem to take into consideration the initial deployment. (Just as an example: https://support.mozilla.org/en-US/questions/859507?as=aaq) I'd like to be able to

  • Several key figures in one colume in P&L report

    Hello! Please, say me about decision of my problem: I hame hierarchy 0GL_ACCOUNT in P&L report, key figure is 0Balance. Items of P&L connected with one or more accounts. But for several accounts I need new key figure (not 0Balance), which calculated

  • Using Photoshop elements 9 with two monitors

    I used Photel 6 with no problem on my Macbook Pro + Lacie 324 monitor, and used to slide the photo on the LaCie and keep the tools on the Macbook Pro screen. I just installed Photel 9 and I cannot do that anymore. Does anyone know why and tell me how