JAVA调用BAPI创建销售订单
2010-09-26 19:39
381 查看
1、复制BAPI_SALESORDER_CREATEFROMDAT2到函数ZRFC_SALESORDER_CREATEFROMDAT,封装BAPI_TRANSACTION_COMMIT。
2、创建JAVA程序
import java.io.File;
import java.io.FileOutputStream;
import java.util.Properties;
import com.sap.conn.jco.JCoException;
import com.sap.conn.jco.ext.DestinationDataProvider;
import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoDestinationManager;
import com.sap.conn.jco.AbapException;
import com.sap.conn.jco.JCoFunction;
import com.sap.conn.jco.JCoField;
import com.sap.conn.jco.JCoStructure;
import com.sap.conn.jco.JCoTable;
public class CreateOrder {
static String ABAP_AS_POOLED = "ABAP_AS_WITH_POOL";
static
{
Properties connectProperties = new Properties();
connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "192.168.00");
connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, "10");
connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "100");
connectProperties.setProperty(DestinationDataProvider.JCO_USER, "LIUWL");
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "ADMIN123");
connectProperties.setProperty(DestinationDataProvider.JCO_LANG, "ZH");
//JCO_PEAK_LIMIT - Maximum number of idle connections kept open by the destination.
connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, "3");
//JCO_POOL_CAPACITY - Maximum number of active connections that
//can be created for a destination simultaneously
connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, "10");
createDataFile(ABAP_AS_POOLED, "jcoDestination", connectProperties);
}
static void createDataFile(String name, String suffix, Properties properties)
{
File cfg = new File(name+"."+suffix);
if(!cfg.exists())
{
try
{
FileOutputStream fos = new FileOutputStream(cfg, false);
properties.store(fos, "for tests only !");
fos.close();
}
catch (Exception e)
{
throw new RuntimeException("Unable to create the destination file " + cfg.getName(), e);
}
}
}
public static void createSAPOrder() throws JCoException
{
JCoDestination destination = JCoDestinationManager.getDestination(ABAP_AS_POOLED);
JCoFunction function = destination.getRepository().getFunction("ZRFC_SALESORDER_CREATEFROMDAT");
if(function == null)
throw new RuntimeException("BAPI_SALESORDER_CREATEFROMDAT2 not found in SAP.");
//importing parameter
JCoStructure salehd = function.getImportParameterList().getStructure("ORDER_HEADER_IN");
JCoStructure salehdx = function.getImportParameterList().getStructure("ORDER_HEADER_INX");
//Tables
JCoTable returntable = function.getTableParameterList().getTable("RETURN");
JCoTable item = function.getTableParameterList().getTable("ORDER_ITEMS_IN");
JCoTable itemx = function.getTableParameterList().getTable("ORDER_ITEMS_INX");
JCoTable partner = function.getTableParameterList().getTable("ORDER_PARTNERS");
JCoTable schedule = function.getTableParameterList().getTable("ORDER_SCHEDULES_IN");
JCoTable schedulex = function.getTableParameterList().getTable("ORDER_SCHEDULES_INX");
// JCoTable condition = function.getTableParameterList().getTable("ORDER_CONDITIONS_IN");
// JCoTable conditionx = function.getTableParameterList().getTable("ORDER_CONDITIONS_INX");
salehd.setValue("DOC_TYPE","TA"); //订单类型
salehd.setValue("SALES_ORG","8101"); //销售机构
salehd.setValue("DISTR_CHAN","10"); //分销渠道
salehd.setValue("DIVISION","10"); //产品组
salehd.setValue("PURCH_NO_C","12"); //采购订单编号
salehd.setValue("PRICE_DATE","20100926");//定价日期
salehd.setValue("PMNTTRMS","0002"); //付款条款
salehdx.setValue("DOC_TYPE","X"); //订单类型
salehdx.setValue("SALES_ORG","X"); //销售机构
salehdx.setValue("DISTR_CHAN","X"); //分销渠道
salehdx.setValue("DIVISION","X"); //产品组
salehdx.setValue("PURCH_NO_C","X"); //采购订单编号
salehdx.setValue("PRICE_DATE","X");//定价日期
salehdx.setValue("PMNTTRMS","X"); //付款条款
item.appendRow();
item.setValue("ITM_NUMBER","000010"); //项目
item.setValue("MATERIAL","000000000000000007"); //物料编号
itemx.appendRow();
itemx.setValue("ITM_NUMBER","000010"); //项目
itemx.setValue("MATERIAL","X"); //物料编号
schedule.appendRow();
schedule.setValue("ITM_NUMBER","000010");//项目
schedule.setValue("SCHED_LINE","0001");//计划行
schedule.setValue("REQ_QTY","10");//数量
schedulex.appendRow();
schedulex.setValue("ITM_NUMBER","000010");//项目
schedulex.setValue("SCHED_LINE","0001");//计划行
schedulex.setValue("REQ_QTY","X");//数量
partner.appendRow();
partner.setValue("PARTN_ROLE","AG"); //售达方
partner.setValue("PARTN_NUMB","0000100043"); //售达方编号
partner.appendRow();
partner.setValue("PARTN_ROLE","WE"); //运达方
partner.setValue("PARTN_NUMB","0000100043"); //运达方编号
try
{
function.execute(destination);
}
catch(AbapException e)
{
System.out.println(e.toString());
return;
}
String saledocu = function.getExportParameterList().getString("SALESDOCUMENT");
System.out.println("创建订单:"+saledocu);
System.out.println("返回信息数:"+returntable.getNumRows());
for(int j = 0; j< returntable.getNumRows();j++)
{
for(int i = 0; i < returntable.getMetaData().getFieldCount(); i++)
{
System.out.println(returntable.getMetaData().getName(i) + ":/t" + returntable.getString(i));
}
returntable.nextRow();
System.out.println();
}
}
public static void main(String[] args) throws JCoException
{
createSAPOrder();
}
}
3、执行结果
注意:
创建时,订单类型等参数必须使用德语代码
BAPI_SALESORDER_CREATEFROMDAT2不可创建退货订单
2、创建JAVA程序
import java.io.File;
import java.io.FileOutputStream;
import java.util.Properties;
import com.sap.conn.jco.JCoException;
import com.sap.conn.jco.ext.DestinationDataProvider;
import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoDestinationManager;
import com.sap.conn.jco.AbapException;
import com.sap.conn.jco.JCoFunction;
import com.sap.conn.jco.JCoField;
import com.sap.conn.jco.JCoStructure;
import com.sap.conn.jco.JCoTable;
public class CreateOrder {
static String ABAP_AS_POOLED = "ABAP_AS_WITH_POOL";
static
{
Properties connectProperties = new Properties();
connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "192.168.00");
connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, "10");
connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "100");
connectProperties.setProperty(DestinationDataProvider.JCO_USER, "LIUWL");
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "ADMIN123");
connectProperties.setProperty(DestinationDataProvider.JCO_LANG, "ZH");
//JCO_PEAK_LIMIT - Maximum number of idle connections kept open by the destination.
connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, "3");
//JCO_POOL_CAPACITY - Maximum number of active connections that
//can be created for a destination simultaneously
connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, "10");
createDataFile(ABAP_AS_POOLED, "jcoDestination", connectProperties);
}
static void createDataFile(String name, String suffix, Properties properties)
{
File cfg = new File(name+"."+suffix);
if(!cfg.exists())
{
try
{
FileOutputStream fos = new FileOutputStream(cfg, false);
properties.store(fos, "for tests only !");
fos.close();
}
catch (Exception e)
{
throw new RuntimeException("Unable to create the destination file " + cfg.getName(), e);
}
}
}
public static void createSAPOrder() throws JCoException
{
JCoDestination destination = JCoDestinationManager.getDestination(ABAP_AS_POOLED);
JCoFunction function = destination.getRepository().getFunction("ZRFC_SALESORDER_CREATEFROMDAT");
if(function == null)
throw new RuntimeException("BAPI_SALESORDER_CREATEFROMDAT2 not found in SAP.");
//importing parameter
JCoStructure salehd = function.getImportParameterList().getStructure("ORDER_HEADER_IN");
JCoStructure salehdx = function.getImportParameterList().getStructure("ORDER_HEADER_INX");
//Tables
JCoTable returntable = function.getTableParameterList().getTable("RETURN");
JCoTable item = function.getTableParameterList().getTable("ORDER_ITEMS_IN");
JCoTable itemx = function.getTableParameterList().getTable("ORDER_ITEMS_INX");
JCoTable partner = function.getTableParameterList().getTable("ORDER_PARTNERS");
JCoTable schedule = function.getTableParameterList().getTable("ORDER_SCHEDULES_IN");
JCoTable schedulex = function.getTableParameterList().getTable("ORDER_SCHEDULES_INX");
// JCoTable condition = function.getTableParameterList().getTable("ORDER_CONDITIONS_IN");
// JCoTable conditionx = function.getTableParameterList().getTable("ORDER_CONDITIONS_INX");
salehd.setValue("DOC_TYPE","TA"); //订单类型
salehd.setValue("SALES_ORG","8101"); //销售机构
salehd.setValue("DISTR_CHAN","10"); //分销渠道
salehd.setValue("DIVISION","10"); //产品组
salehd.setValue("PURCH_NO_C","12"); //采购订单编号
salehd.setValue("PRICE_DATE","20100926");//定价日期
salehd.setValue("PMNTTRMS","0002"); //付款条款
salehdx.setValue("DOC_TYPE","X"); //订单类型
salehdx.setValue("SALES_ORG","X"); //销售机构
salehdx.setValue("DISTR_CHAN","X"); //分销渠道
salehdx.setValue("DIVISION","X"); //产品组
salehdx.setValue("PURCH_NO_C","X"); //采购订单编号
salehdx.setValue("PRICE_DATE","X");//定价日期
salehdx.setValue("PMNTTRMS","X"); //付款条款
item.appendRow();
item.setValue("ITM_NUMBER","000010"); //项目
item.setValue("MATERIAL","000000000000000007"); //物料编号
itemx.appendRow();
itemx.setValue("ITM_NUMBER","000010"); //项目
itemx.setValue("MATERIAL","X"); //物料编号
schedule.appendRow();
schedule.setValue("ITM_NUMBER","000010");//项目
schedule.setValue("SCHED_LINE","0001");//计划行
schedule.setValue("REQ_QTY","10");//数量
schedulex.appendRow();
schedulex.setValue("ITM_NUMBER","000010");//项目
schedulex.setValue("SCHED_LINE","0001");//计划行
schedulex.setValue("REQ_QTY","X");//数量
partner.appendRow();
partner.setValue("PARTN_ROLE","AG"); //售达方
partner.setValue("PARTN_NUMB","0000100043"); //售达方编号
partner.appendRow();
partner.setValue("PARTN_ROLE","WE"); //运达方
partner.setValue("PARTN_NUMB","0000100043"); //运达方编号
try
{
function.execute(destination);
}
catch(AbapException e)
{
System.out.println(e.toString());
return;
}
String saledocu = function.getExportParameterList().getString("SALESDOCUMENT");
System.out.println("创建订单:"+saledocu);
System.out.println("返回信息数:"+returntable.getNumRows());
for(int j = 0; j< returntable.getNumRows();j++)
{
for(int i = 0; i < returntable.getMetaData().getFieldCount(); i++)
{
System.out.println(returntable.getMetaData().getName(i) + ":/t" + returntable.getString(i));
}
returntable.nextRow();
System.out.println();
}
}
public static void main(String[] args) throws JCoException
{
createSAPOrder();
}
}
3、执行结果
注意:
创建时,订单类型等参数必须使用德语代码
BAPI_SALESORDER_CREATEFROMDAT2不可创建退货订单
相关文章推荐
- JAVA调用BAPI创建销售订单
- BAPI_SALESORDER_CREATEFROMDAT2 BAPI创建VA01 销售订单
- 关于通过使用BAPI创建销售订单(抬头信息中:含增强字段)
- BAPI:BAPI_SALESORDER_CREATEFROMDAT2 创建销售订单
- 调用SAP函数创建寄售退货订单的时候报错:业务对象 BUS2032 是销售订单,销售凭证类别 H 是退货。
- ABAP模块-根据销售订单创建交货单BAPI
- 创建销售订单BAPI一些心得
- BAPI:BAPI_SALESORDER_CREATEFROMDAT2 创建销售订单
- BAPI调用 - 创建SO出现错误"不允许业务对象 BUS2032 和销售凭证类别 H 的组合"
- 关于通过使用BAPI创建销售订单(抬头信息中:含增强字段)
- 关于通过使用BAPI创建销售订单(抬头信息中:含增强字段)
- BAPI:BAPI_SALESORDER_CREATEFROMDAT2 创建销售订单
- Oracle存储过程创建及调用 java调用oracle存储过程的示例总结
- oe_order_pub 创建 登记 销售订单
- Java之Object构造方法(创建子类对父类构造方法的调用)
- 调用BAPI_MATERIAL_SAVEDATA批量创建物料代码示例
- 根据BAPI_PO_CREATE1创建采购订单
- jstack应用实例,java方法调用阻塞实例,dubbo创建消费者阻塞。
- java使用xfire创建和调用webservices
- 10.5在Java中创建与传递Groovy闭包(在java中调用groovy方法,并且传递闭包参数)