vba 如何将数据从 SAP 表导入 Excel 表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8178876/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 14:28:49  来源:igfitidea点击:

How can I import data from SAP Table to an Excel Sheet

excelexcel-vbasapvba

提问by user1049518

I am new to Excel VBA. I don't know how to get the data from SAP table to Excel sheet.

我是 Excel VBA 的新手。我不知道如何将数据从 SAP 表获取到 Excel 表。

The query is. I have one Excel sheet containing 10 fields.
Basing on pcodefield (in Excel), PLwill be imported from SAP table.

查询是。我有一张包含 10 个字段的 Excel 工作表。
基于pcode字段(在 Excel 中),PL将从 SAP 表中导入。

Example

例子

ID | name  | pcode | PL (from SAP)
---+-------+-------+-----------------
1  | kiran | 1234  | 
2  | karan | 5001  | 

回答by Cal

There's a lot of documentation online for writing into Excel sheets from VB, as there is a lot of documentation for reading SQL table data into VB, you can google these things and find what you need. Something you might not find through Google is how to track down the tables you actually require. SAP data all comes from tables that I like to call "Background" tables. Although SAP presents all the data in a nice format which is easy on the eyes, it is all actually just a set of big ugly SQL tables. Lets say I want to extract all of the items that I have in stock (as far as SAP knows), then write this info into an excel sheet, here's where to begin:

网上有很多关于从 VB 写入 Excel 表格的文档,因为有很多用于将 SQL 表数据读入 VB 的文档,您可以在 google 上搜索这些内容并找到您需要的内容。您可能无法通过 Google 找到的内容是如何追踪您实际需要的表格。SAP 数据全部来自我喜欢称为“背景”表的表。尽管 SAP 以一种很好看的格式呈现所有数据,但实际上它只是一组丑陋的大 SQL 表。假设我想提取我库存中的所有项目(据 SAP 所知),然后将此信息写入 Excel 表,这里是开始的地方:

Firstly TURN ON SYSTEM INFORMATION. To do this, press Ctrl + Shift + I (or go to View -> system information), now when you hover over a field, the bar at the bottom of the SAP screen will tell you all of the background information that you'll need to find the location of the data in SQL.

首先打开系统信息。为此,请按 Ctrl + Shift + I(或转到“查看”->“系统信息”),现在当您将鼠标悬停在某个字段上时,SAP 屏幕底部的栏会告诉您所有的背景信息需要在SQL中找到数据的位置。

Hover mouse somewhere and look here!

将鼠标悬停在某处,然后看这里!

When you hover your cursor over a field, the bar highlighted in this image should show something like this:

当您将光标悬停在某个字段上时,此图像中突出显示的栏应显示如下内容:

Manual [Form = 142 Item = 38 Pane = 1 Column = 14700021 Row = 1 Variable = 11 POR1,UomCode]

手册 [表单 = 142 项 = 38 窗格 = 1 列 = 14700021 行 = 1 变量 = 11 POR1,UomCode]

Here the parts we are interested are the "POR1, UomCode" Here, "POR1" will be the name of the SQL table which contains the data you're after, and "UomCode" is the column name.

这里我们感兴趣的部分是“POR1,UomCode”。这里,“POR1”将是包含您要查找的数据的 SQL 表的名称,“UomCode”是列名称。

This example was for a purchase order, but for item master data this information will be different, the table name will be OITM, with item details being held in ITM1.

此示例针对采购订单,但对于物料主数据,此信息将有所不同,表名称将为 OITM,物料详细信息保存在 ITM1 中。

And so you would contruct a SQL query which will bring through all the info you need from the tables, package it up into variables in whatever programming language you choose (I use VB.NET), then spit it out into Excel.

因此,您将构建一个 SQL 查询,该查询将从表中获取您需要的所有信息,以您选择的任何编程语言(我使用 VB.NET)将其打包成变量,然后将其输出到 Excel 中。

Hope this helped!

希望这有帮助!