1. sap 多条件查询语句,根据function中的IMPORTING 中有 I_VBELN , I_ERDAT, I_ERNAM,三个参数(参照vbak
定义三个对应的range变量 I_VBELN,I_ERDAT,I_TRVOG为区间变量
where语句中这样写:where vbak~vbeln in i_vbeln
and vbak~erdat in i_erdat
and vbak~trvog in i_trvog
结果导出就可以了
2. 关于java 通过rfc接口获取sap中的数据,tableParams返回的是二维的数据吗,还有如何获取其中的值
JCO.ParameterList tableParams = function.getTableParameterList();是指获得RFC中Tables参数列表,再用tableParams.getTable()方法可以获得JCoTable table,获得具体数据表需要利用table.firstRow()、table.nextRow();table.getString();table.getDouble()等方法遍历取得个字段的值,getFieldCount()和getNumRows()可以分别获得table的列数和行数。
3. java怎么连接db数据库文件
private static JdbcTemplate getJdbcTemplate(DynamicDataSourceEntity dynamicSourceEntity) { BasicDataSource dataSource = getDataSource(dynamicSourceEntity); JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); return jdbcTemplate; } public static void main(String[] args) { DynamicDataSourceEntity dynamicSourceEntity = new DynamicDataSourceEntity(); String dbKey = "SAP_DB"; String driverClassName = "oracle.jdbc.driver.OracleDriver"; String url = "jdbc:oracle:thin:@10.10.0.59:1521:mid"; String dbUser = "CRM"; String dbPassword = "CRM2013"; dynamicSourceEntity.setDbKey(dbKey); dynamicSourceEntity.setDriverClass(driverClassName); dynamicSourceEntity.setUrl(url); dynamicSourceEntity.setDbUser(dbUser); dynamicSourceEntity.setDbPassword(dbPassword); JdbcTemplate jdbcTemplate = getJdbcTemplate(dynamicSourceEntity); String sql = "select ak.VKBUR, ak.KUNNR, ak.BSTNK, ak.VBELN, ak.MAHDT, ak.BSTDK from VBAK ak where ak.VKORG = '6002'"; //List> list = DynamicDBUtil.getList(jdbcTemplate, sql); //System.out.println(list.size()); }
4. SAP 将不同表中的字段选入到一张内表中去
为啥一定要用loop来做,这么简单的表,用query几分钟就完事了。
5. SAP 销售订单里的送达方如何对应
VBAK-KUNNR是售达方
LIKP-KUNNR是送达方 LIKP-KUNAG是售达方
这是俩不一样的字段 如果说这个订单送达方与售达方都是一样的 那么字段的值当然一样
如果售达方与送达方不一定一样 那么就会不一样
比如我做了一张销售订单so1:售达方 1001 送达方1001001
那么VBAK-KUNNR = 1001 LIKP-KUNNR = 1001001 LIKP-KUNAG = 1001
另外,销售凭证所有的合作伙伴都可以在VBPA里面取到
6. JAVA怎么才能调用SAP的函数?谢谢
给你举个例子吧,如下:
1:Sap 域模型
package abc;
public class SapSystem implements java.lang.Cloneable {
private final String name;
private final String host;
private final String client;
private final String systemNumber;
private final String user;
private final String password;
private final String language ="en"; // English will be used as login language
/**
* Constructor, Login language is assumed to be English
* @param name
* @param client
* @param user
* @param password
* @param host
* @param systemNumber
*/
public SapSystem(String name, String host, String client
, String systemNumber, String user, String password) {
this.name = name;
this.client = client;
this.user = user;
this.password = password;
this.host = host;
this.systemNumber = systemNumber;
}
public String getName() {
return name;
}
public String getClient() {
return client;
}
public String getUser() {
return user;
}
public String getPassword() {
return password;
}
public String getLanguage() {
return language;
}
public String getHost() {
return host;
}
public String getSystemNumber() {
return systemNumber;
}
@Override
public String toString() {
return "Client " + client + " User " + user + " PW " + password
+ " Language " + language + " Host " + host + " SysID "
+ systemNumber;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((client == null) ? 0 : client.hashCode());
result = prime * result + ((host == null) ? 0 : host.hashCode());
result = prime * result
+ ((language == null) ? 0 : language.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result
+ ((password == null) ? 0 : password.hashCode());
result = prime * result
+ ((systemNumber == null) ? 0 : systemNumber.hashCode());
result = prime * result + ((user == null) ? 0 : user.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
SapSystem other = (SapSystem) obj;
if (client == null) {
if (other.client != null)
return false;
} else if (!client.equals(other.client))
return false;
if (host == null) {
if (other.host != null)
return false;
} else if (!host.equals(other.host))
return false;
if (language == null) {
if (other.language != null)
return false;
} else if (!language.equals(other.language))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (password == null) {
if (other.password != null)
return false;
} else if (!password.equals(other.password))
return false;
if (systemNumber == null) {
if (other.systemNumber != null)
return false;
} else if (!systemNumber.equals(other.systemNumber))
return false;
if (user == null) {
if (other.user != null)
return false;
} else if (!user.equals(other.user))
return false;
return true;
}
@Override
public Object clone() {
try {
return super.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
return null;
}
}
=====================================
2:建立连接
import java.util.Properties;
import com.sap.conn.jco.ext.DestinationDataEventListener;
import com.sap.conn.jco.ext.DestinationDataProvider;
import de.vogella.sap.system.model.SapSystem;
/**
* Represents the destination to a specific SAP system.
* The destination is maintained via a property file
*
*/
public class MyDestinationDataProvider implements DestinationDataProvider {
static String SAP_SERVER = "SAP_SERVER";
private final Properties ABAP_AS_properties;
public MyDestinationDataProvider(SapSystem system) {
Properties properties = new Properties();
properties.setProperty(DestinationDataProvider.JCO_ASHOST, system
.getHost());
properties.setProperty(DestinationDataProvider.JCO_SYSNR, system
.getSystemNumber());
properties.setProperty(DestinationDataProvider.JCO_CLIENT, system
.getClient());
properties.setProperty(DestinationDataProvider.JCO_USER, system
.getUser());
properties.setProperty(DestinationDataProvider.JCO_PASSWD, system
.getPassword());
ABAP_AS_properties = properties;
}
@Override
public Properties getDestinationProperties(String system) {
return ABAP_AS_properties;
}
@Override
public void setDestinationDataEventListener(
DestinationDataEventListener eventListener) {
}
@Override
public boolean supportsEvents() {
return false;
}
}
==================
import com.sap.conn.jco.JCoContext;
import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoDestinationManager;
import com.sap.conn.jco.JCoException;
import com.sap.conn.jco.JCoFunction;
import com.sap.conn.jco.JCoRepository;
import de.vogella.sap.system.model.SapSystem;
/**
* Connection allows to get and execute SAP functions. The constructor expect a
* SapSystem and will save the connection data to a file. The connection will
* also be automatically be established.
*/
public class Connection {
static String SAP_SERVER = "SAP_SERVER";
private JCoRepository repos;
private JCoDestination dest;
public Connection(SapSystem system) {
MyDestinationDataProvider myProvider = new MyDestinationDataProvider(system);
com.sap.conn.jco.ext.Environment
.registerDestinationDataProvider(myProvider);
try {
dest = JCoDestinationManager.getDestination(SAP_SERVER);
System.out.println("Attributes:");
System.out.println(dest.getAttributes());
repos = dest.getRepository();
} catch (JCoException e) {
throw new RuntimeException(e);
}
}
/**
* Method getFunction read a SAP Function and return it to the caller. The
* caller can then set parameters (import, export, tables) on this function
* and call later the method execute.
*
* getFunction translates the JCo checked exceptions into a non-checked
* exceptions
*/
public JCoFunction getFunction(String functionStr) {
JCoFunction function = null;
try {
function = repos.getFunction(functionStr);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(
"Problem retrieving JCO.Function object.");
}
if (function == null) {
throw new RuntimeException("Not possible to receive function. ");
}
return function;
}
/**
* Method execute will call a function. The Caller of this function has
* already set all required parameters of the function
*
*/
public void execute(JCoFunction function) {
try {
JCoContext.begin(dest);
function.execute(dest);
} catch (JCoException e) {
e.printStackTrace();
} finally {
try {
JCoContext.end(dest);
} catch (JCoException e) {
e.printStackTrace();
}
}
}
}
======================
3:测试连接
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import com.sap.conn.jco.JCoFunction;
import com.sap.conn.jco.JCoTable;
import de.vogella.sap.rfc.core.connection.Connection;
import de.vogella.sap.system.model.SapSystem;
public class ConnectionTester {
static String SAP = "SAP_SERVER";
@Test
public void checkConnection() {
// SAP System
SapSystem system = new SapSystem("PFT", "pwdf6394.wdf.sap.corp", "600", "76", "mytester", "welcome");
Connection connect = new Connection(system);
JCoFunction function = connect.getFunction("BAPI_USER_GETLIST");
function.getImportParameterList().setValue("MAX_ROWS", 10);
connect.execute(function);
JCoTable table = function.getTableParameterList().getTable("USERLIST");
assertTrue("User Tabelle should not be empty", !table.isEmpty());
}
}
======================
4:简化JCo存取
import com.sap.conn.jco.JCoTable;
/**
* TableAdapter is used to simplify the reading of the values of the Jco tables
*/
public class TableAdapterReader {
protected JCoTable table;
public TableAdapterReader(JCoTable table) {
this.table = table;
}
public String get(String s) {
return table.getValue(s).toString();
}
public Boolean getBoolean(String s) {
String value = table.getValue(s).toString();
return value.equals("X");
}
public String getMessage() {
return table.getString("MESSAGE");
}
public int size() {
return table.getNumRows();
}
public void next() {
table.nextRow();
}
}
5:最后测试
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import com.sap.conn.jco.JCoFunction;
import com.sap.conn.jco.JCoTable;
import de.vogella.sap.rfc.core.connection.Connection;
import de.vogella.sap.rfc.helper.TableAdapterReader;
import de.vogella.sap.system.model.SapSystem;
public class TableAdapterTester {
@Test
public void checkConnection() {
// SAP System
SapSystem system = new SapSystem("PFT", "pwdf6394.wdf.sap.corp", "600",
"76", "mytester", "welcome");
Connection connect = new Connection(system);
JCoFunction function = connect.getFunction("BAPI_USER_GETLIST");
function.getImportParameterList().setValue("MAX_ROWS", 10);
connect.execute(function);
JCoTable table = function.getTableParameterList().getTable("USERLIST");
TableAdapterReader adapter = new TableAdapterReader(table);
System.out.println("Number of Users: " + adapter.size());
for (int i = 0; i < adapter.size(); i++) {
// USERNAME is a column in the table "USERLIST"
String s = adapter.get("USERNAME");
assertNotNull(s);
assertTrue(s.length() > 0);
System.out.println(s);
adapter.next();
}
assertTrue("User Tabelle should not be empty", !table.isEmpty());
}
}
7. SAP调用BAPI创建物料主数据
import com.sap.mw.jco.*;
import com.sap.mw.jco.JCO;
import com.sap.mw.jco.IFunctionTemplate;
import com.sap.mw.jco.JCO.Structure;
public class Create_Item extends Connect_Sap_Server{
private JCO.Client mConnection = this.getConnection();
private JCO.Repository mRepository = new JCO.Repository("Repository", mConnection);
private JCO.Function function = null;
private JCO.Table data = null;
private String[] SAPInterfaces;
public Create_Item(){
try {
function = this.createFunction("BAPI_MATERIAL_SAVEDATA");
if (function == null) {
System.out.println("BAPI_MATERIAL_SAVEDATA"
+ " not found in SAP.");
System.out.println("SAP_RFC中没有此函数!");
System.exit(1);
}
JCO.Structure head_data = function.getImportParameterList().getStructure("HEADDATA");
head_data.setValue("00000000999914886", "MATERIAL"); //物料号
head_data.setValue("ROH", "MATL_TYPE"); //物料类型
head_data.setValue("M", "IND_SECTOR"); //行业领域(L、零售;A、工厂工程/结构;C、化学工业;M、机械工程;P、药品)
head_data.setValue("X", "BASIC_VIEW"); //基本数据视图
head_data.setValue("X", "PURCHASE_VIEW"); //采购视图
head_data.setValue("X", "ACCOUNT_VIEW"); //会计视图
// head_data.setValue("X", "SALES_VIEW"); //销售视图
head_data.setValue("X", "MRP_VIEW"); //物料需求计划(MRP)视图
//物料描述(MAKT)
JCO.Table mtl_desc = function.getTableParameterList().getTable("MATERIALDESCRIPTION");
mtl_desc.appendRow();
mtl_desc.setValue(this.changecode("神奇的钻头【java开发测试用物料】"), "MATL_DESC");//物料描述
mtl_desc.setValue("ZH", "LANGU_ISO");
mtl_desc.setValue("1", "LANGU");
//客户端层次物料数据(MARA)
JCO.Structure client_data = function.getImportParameterList().getStructure("CLIENTDATA");
client_data.setValue("999914886", "MATERIAL");
client_data.setValue("ST", "BASE_UOM"); //基本计量单位
client_data.setValue("ST", "BASE_UOM_ISO"); //ISO 代码的计量基本单位
client_data.setValue("01", "MATL_GROUP"); //物料组
//client_data.setValue("", "EXTMATLGRP"); //外部物料组
client_data.setValue("X", "ENVT_RLVT"); //关键件标识
//========start====
//此处必须写如果不写会报“字段MARA-MEINS/BAPI_MARA-BASE_UOM(_ISO)被定义为必需的字段; 它不包含条目”
//等错误并且在SAP中看不到相应的数据
JCO.Structure clientx_data = function.getImportParameterList().getStructure("CLIENTDATAX");
clientx_data.setValue("ST", "BASE_UOM");
clientx_data.setValue("ST", "BASE_UOM_ISO");
clientx_data.setValue("01", "MATL_GROUP"); //物料组
clientx_data.setValue("", "EXTMATLGRP"); //外部物料组
//========end======
//工厂级别的物料数据(MARC)
JCO.Structure plant_data = function.getImportParameterList().getStructure("PLANTDATA");
plant_data.setValue("2005", "PLANT"); //工厂
plant_data.setValue("Z48", "PUR_GROUP"); //采购组
plant_data.setValue("KP", "AVAILCHECK"); //可用性检查的检查组
plant_data.setValue("PD", "MRP_TYPE"); //MRP类型
plant_data.setValue("G01", "MRP_CTRLER"); //MRP控制者
plant_data.setValue("000", "SM_KEY"); //计划边际码
plant_data.setValue("EX", "LOTSIZEKEY"); //批量 (物料计划)
JCO.Structure plantx_data = function.getImportParameterList().getStructure("PLANTDATAX");
plantx_data.setValue("2005", "PLANT");
plantx_data.setValue("KP", "AVAILCHECK");
plantx_data.setValue("PD", "MRP_TYPE");
plantx_data.setValue("G01", "MRP_CTRLER");
plantx_data.setValue("000", "SM_KEY");
plantx_data.setValue("EX", "LOTSIZEKEY");
mConnection.execute(function); // 执行配置好的function
JCO.Structure returnStructure = function.getExportParameterList().getStructure("RETURN");
if(!(returnStructure.getString("TYPE").equals("") || returnStructure.getString("TYPE").equals("S"))){
System.out.println(returnStructure.getString("MESSAGE"));
throw new Exception("新增数据失败:" + returnStructure.getString("MESSAGE"));
}
function = this.createFunction("BAPI_TRANSACTION_COMMIT");
mConnection.execute(function);
System.out.println("新增物料主数据成功!");
} catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
} finally {
if (mConnection != null) {
mConnection.disconnect();
}
}
}
8. sap abap怎样创建一个structure
types:
begin of i_lips,
vbeln like lips-vbeln, "交货单号
posnr like lips-posnr, "交货项目
matnr like lips-matnr, "物料号
kdmat like lips-kdmat, "客户物料
lfimg like lips-lfimg, "实际已交货数
meins like lips-meins, "基本计量单位
vrkme like lips-vrkme, "销售单位
brgew like lips-brgew, "净重量
vgbel like lips-vgbel, "参考单据的单据编号
vgpos like lips-vgpos, "参考项目的项目号
auart like vbak-auart, "销售凭证类型
kbetr like konv-kbetr, "价格( 条件金额或百分数 )
kpein like konv-kpein, "条件定价单位
kmein like konv-kmein, "在凭证中的条件单位
kunag like likp-kunag, "售达方
kunnr like likp-kunnr, "送达方
erdat like likp-erdat, "记录创建日期
knumv like vbak-knumv, "单据条件数 价格指针
lgort like lips-lgort, "库存地
lfart like likp-lfart, "交货类型 ZLR 为退货交货订单
end of i_lips.