搜档网
当前位置:搜档网 › oa与sap接口java后台代码编写说明window版本

oa与sap接口java后台代码编写说明window版本

oa与sap接口java后台代码编写说明window版本
oa与sap接口java后台代码编写说明window版本

oa与sap接口后台java接口说明

(window版本)

后台java处理页面分为三个sapconn.java sap连接java XSJGSPAction.java数据获取的javaXSJGSPHXAction.java数据回写的java

Sapconn.java编写说明

内容以及编写说明(该类不需要修改)

packageweaver.interfaces.workflow.action;

importjavax.swing.JOptionPane;

importcom.sap.mw.jco.*;

importweaver.general.BaseBean;

public class SAPConn extends javax.swing.JFrame{

final static long serialVersionUID=90;

final static String POOL_NAME = "Pool";

private static JCO.ClientmConnection=null;

private static BaseBean bb = new BaseBean();

private static String sapclient = "";

private static String userid = "";

private static String password = "";

private static String hostname = "";

private static String systemnumber = "";

private static String Language = "";

/*

*初始化连接

*/

public void SAPConn () {

}

/*

*初始化连接

*/

private void init(){

try{//读取配置文件信息

bb.writeLog("-------------SAP Client Connects Start ----------------");

sapclient = bb.getPropValue("SAPConn", "SAPClient");

userid = bb.getPropValue("SAPConn", "Userid");

password = bb.getPropValue("SAPConn", "Password");

hostname = bb.getPropValue("SAPConn", "HostName");

systemnumber = bb.getPropValue("SAPConn", "SystemNumber");

Language = bb.getPropValue("SAPConn", "Language");

JCO.Pool pool = JCO.getClientPoolManager().getPool(POOL_NAME);

if (pool == null) {

JCO.addClientPool(POOL_NAME, // pool name

100, // maximum number of connections

sapclient,

userid,

password,

Language,

hostname,

systemnumber);

}

setConnection(JCO.getClient(POOL_NAME));//获取连接

bb.writeLog("get connection success");

}catch (Exception e) {

bb.writeLog("get connection error:"+e);

}

}

/*

*释放连接

*/

public void releaseC(){

if(mConnection!=null)

JCO.releaseClient(mConnection);

}

/*

*获取连接

*/

publicJCO.ClientgetConnection(){

if (mConnection==null)

{

init();

}

returnmConnection;

}

/*

*设置连接

*/

public void setConnection(JCO.Client conn){

mConnection = conn;

}

/*

*执行Bapi

*/

publicJCO.FunctionexcuteBapi(String s) {

System.out.println("GET INTO Function Bapi!");

SAPConnsapconn = new SAPConn();

JCO.Clientsapconnection = sapconn.getConnection();

JCO.RepositorymRepository;

JCO.FunctionjcoFunction = null;

System.out.println("sapconnection=="+sapconnection);

if(sapconnection==null) return jcoFunction;

try {

mRepository = new JCO.Repository("sap", sapconnection);

System.out.println("mRepository=="+mRepository);

IFunctionTemplateft = mRepository.getFunctionTemplate(s);

jcoFunction = new JCO.Function(ft);

System.out.println("excueteBapi Success");

returnjcoFunction;

} catch (Exception e) {

System.out.println(e);

JOptionPane.showMessageDialog(null, e.getMessage(), "错误信息", 0);

return null;

} finally {

}

}

}

数据获取XSJGSPAction.java编写说明

内容以及编写说明

packageweaver.interfaces.workflow.action;

importjava.util.List;

importjava.util.ArrayList;

importjava.util.Map;

importjava.util.HashMap;

importjavax.swing.JOptionPane;

importweaver.general.TimeUtil;

importcom.sap.mw.jco.JCO;

importcom.sap.mw.jco.JCO.Table;

importcom.sap.mw.jco.JCO.Record;

importcom.sap.mw.jco.IFunctionTemplate;

//oa系统文件

public class XSJGSPAction {

//生成jco对象对sap进行操作的对象

privateJCO.Clientsapconnection = new SAPConn().getConnection();

privateintcursorindex = -1;

privateintdataconts = 0;

privateJCO.Tabledatas = null;

/*

*初始化

*/

public void XSJGSPAction (){

}

/*

*执行Bapi不需要修改

*/

publicJCO.FunctionexcuteBapi(String s) {

System.out.println("GET INTO Function Bapi!");

SAPConnsapconn = new SAPConn();//生成sap对象

JCO.Clientsapconnection = sapconn.getConnection();//获取连接

JCO.RepositorymRepository;

JCO.FunctionjcoFunction = null;//生成function对象

System.out.println("sapconnection=="+sapconnection);

if(sapconnection==null) return jcoFunction;

try {

mRepository = new JCO.Repository("sap", sapconnection);

System.out.println("mRepository=="+mRepository);

IFunctionTemplateft = mRepository.getFunctionTemplate(s);

jcoFunction = new JCO.Function(ft);

System.out.println("excueteBapi Success");

returnjcoFunction;

} catch (Exception e) {

System.out.println(e);

JOptionPane.showMessageDialog(null, e.getMessage(), "错误信息", 0);

return null;

} finally {

}

}

//编写数据获取类

public List Getexecute(String lv_vbeln) {

List list = new ArrayList();

try {

cursorindex = -1;

dataconts = 0;

datas = null;

Map mmap = null;

Map dmap = null;

List mlist = new ArrayList();//存放主表数据

List dlist = new ArrayList();//存放明细表数据

//function name执行sap提供的接口参数为接口名称

JCO.Functionbapi = excuteBapi("ZXSDDSPJK");//ZFUN_OA_CREATEPR ZXSDDSPJK zxsddspjk

// input value

String LV_VBELN = lv_vbeln;

//设置输入参数

bapi.getImportParameterList().setValue(LV_VBELN,"LV_VBELN");//lv_vbeln

sapconnection.execute(bapi);//执行接口

//datas=bapi.getTableParameterList().getTable("SPXM");

String MESSAGEFX = (String) bapi.getExportParameterList().getValue("MESSAGE").toString();//获取接口返回值

System.out.println(">>>>>>>>>>>>>>>>>>MESSAGEFX=" + MESSAGEFX);

Table codes = bapi.getTableParameterList().getTable("SPBT");//获取接口返回的表数据

// intcellrow=0;

//cellrow=codes.getgetNumRows();

//String[] maintable=new String[cellrow];

//获取主表信息保存在mlist中

for (int i = 0; i

{

codes.setRow(i);

mmap = new HashMap();

///获取主表中的数据存放如hashmap中;

mmap.put("VBELN",codes.getString("VBELN"));

mmap.put("BSTKD",codes.getString("BSTKD"));

mmap.put("NAME1",codes.getString("NAME1"));

mmap.put("SDFNAME",codes.getString("SDFNAME"));

mmap.put("XSGY" ,codes.getString("XSGY"));

mmap.put("KLIMK",codes.getString("KLIMK"));

mmap.put("SKFOR",codes.getString("SKFOR"));

mmap.put("DDJE",codes.getString("DDJE"));

mmap.put("CE",codes.getString("CE"));

mmap.put("DQSJ",TimeUtil.getCurrentDateString());

mlist.add(mmap);

}

//将主表数据放入到list中

list.add(mlist);

//获取明细表中数据保存在dlist中

Table codesmx = bapi.getTableParameterList().getTable("SPXM");

System.out.println( "-------------"+codesmx.getNumRows());

for (int i = 0; i

{

codesmx.setRow(i);

dmap = new HashMap();

// System.out.println( "-------------"+i+" ----");

// codesmx.setRow(i);

//获取明细数据存放如hashmap中

dmap.put("POSNR", codesmx.getString("POSNR"));

dmap.put("MATNR",codesmx.getString("MATNR"));

dmap.put("TZ", codesmx.getString("TZ"));

dmap.put("KWMENG", codesmx.getString("KWMENG"));

dmap.put("BCJJ", codesmx.getString("BCJJ"));

dmap.put("FBJJ", codesmx.getString("FBJJ"));

dmap.put("DJHJ", codesmx.getString("DJHJ"));

dmap.put("ZKLX", codesmx.getString("ZKLX"));

dmap.put("ZZDJ", codesmx.getString("ZZDJ"));

dmap.put("KZWI1", codesmx.getString("KZWI1"));

dmap.put("KTEXT", codesmx.getString("KTEXT"));

dmap.put("WAERS", codesmx.getString("WAERS"));

dlist.add(dmap);

}

//将明细数据放入list中

list.add(dlist);

System.out.println(">>"+list.size());

}catch (Exception e) {

System.out.println(e);

}

return list;

}

}

回写类XSJGSPHXAction.java

内容以及编写说明

packageweaver.interfaces.workflow.action;

importjava.awt.List;

importjava.awt.peer.LightweightPeer;

https://www.sodocs.net/doc/8b12174173.html,mons.logging.Log;

https://www.sodocs.net/doc/8b12174173.html,mons.logging.LogFactory;

importcom.sap.mw.jco.JCO;

importcom.sap.mw.jco.JCO.Table;

importweaver.conn.RecordSet;

importweaver.general.TimeUtil;

importweaver.general.Util;

importweaver.interfaces.workflow.action.Action;

importweaver.soa.workflow.request.Property;

importweaver.soa.workflow.request.RequestInfo;

importweaver.soa.workflow.request.Cell;

importweaver.soa.workflow.request.DetailTable;

importweaver.soa.workflow.request.Row;

public class XSJGSPHXAction implements Action {

//生成sapconn对象

privateJCO.Clientsapconnection = new SAPConn().getConnection(); private Log log = LogFactory.getLog(XSJGSPHXAction.class.getName());

public Log getLog() {

return log;

}

public void setLog(Log log) {

this.log = log;

}

//回写执行的方法自己编写的方法

public String executexr(String requeststring )

{

String FLAG="E";

String MESSAGE="";

String requesthq=requeststring;

if(requesthq.indexOf("$")>0)

{

SAPConnSAPConn = new SAPConn();

String[] liststr=requesthq.split("\\$");//获取主表明细表数据

if(liststr.length<2)

{

//System.out.println(liststr[0]);

return "E/数据有误vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv!";

}

String mliststr=liststr[0];//主表信息数据以;分割字段格式为:key:value

String dliststr=liststr[1];//明细表多条明细以~分割字段和主表相同

//获取主表信息

String[] mzdliststr=mliststr.split(";");//获取主表明细表数据

String Requestid="";

String Workflowid="";

String XXDBH="";

//System.out.println("suoyou "+requesthq+"主表信息------"+mliststr+"mx------"+dliststr);

for(int i=0;i

{

//获取所有主表信息格式为key:value

String keyvalue=mzdliststr[i];

// System.out.println("主表信息------"+keyvalue);

if(keyvalue.indexOf(":")>0)

{

System.out.println(" ------"+keyvalue);

String[] keyvaluezh=keyvalue.split(":");

if(keyvaluezh.length<2)

{

continue;

}

String key=keyvaluezh[0].toUpperCase();

String value=keyvaluezh[1];

if(key.equals("requestidValue"))

{

Requestid=value;

}else if(key.equals("workflowidValue"))

{

Workflowid=value;

}else if(key.equals("VBELN"))

{

XXDBH=value;

}

}

}

try

{

String PZZD="批准";

JCO.Function function = SAPConn.excuteBapi("ZXSRUT");//执行sap的写入接口function.getImportParameterList().setValue(PZZD,"LV_VERSION");

JCO.Tableinput_table = null;

input_table = function.getTableParameterList().getTable("GT_XSRET");

//获取明细表中数据mxxx+="posnr:"+getkeyzhi("field5864_"+i)+";zklx:"

//+getkeyzhi("field58656_"+i)+";zkje:"+getkeyzhi("field5866_"+i)

//+";hblx:"+getkeyzhi("field5867_"+i)+"~";

//System.out.println(requesthq);

String[] dzdliststr=dliststr.split("~");//获取明细表明细表数据获取明细总行数for(int di=0;di

{

//获取所有明细信息格式为key:value

String mxkeyvalue=dzdliststr[di]; //格式为:key:value;key:value System.out.println("行数"+dzdliststr.length);

if(mxkeyvalue.indexOf(";")>0)

{

String WAERS = ""; //货币类型

String POSNR = ""; //项目编号

String KSCHL = ""; //折扣类型

String KBETR = "0"; //折扣单价

String Z FLAG ="";//编辑类型

String ERDAT = ""; // 货币类型销售单位

String ZKNULL ="";

String[] mxzdkeyvalue=mxkeyvalue.split(";");//格式为key:name

for(int j=0;j

{

String mxzdmxkeyvalue=mxzdkeyvalue[j];

//System.out.println("明细"+mxzdmxkeyvalue);

if(mxzdmxkeyvalue.indexOf(":")>0)

{

String[] keyvalue=mxzdmxkeyvalue.split(":");

String key=keyvalue[0].toUpperCase();

String value="";

if(keyvalue.length>=2)

{

value=keyvalue[1];

}

System.out.println("字段"+keyvalue.length+" "+key+"---"+value);

if(key.equals("WAERS"))//货币类型

{

WAERS=value;

}else if(key.equals("POSNR"))//行项目号

{

POSNR=value;

}else if(key.equals("KSCHL"))//折扣类型

{

KSCHL = value;

//System.out.println("折扣:"+KSCHL+"cccccccccc"+value+"vvvv");

ZKNULL=KSCHL;

}else if(key.equals("KBETR"))//折扣金额

{

if(value.equals(""))

{

}

else

{

KBETR = value;

}

if(KBETR.equals("0"))

{

ZFLAG="D";

}

else

{

ZFLAG="U";

}

}

}

}

System.out.println("是否u跳过"+ZKNULL+"---"+ZKNULL.equals(""));

if(ZKNULL.equals(""))

{

continue;

}

System.out.println("uuuuuuu:"+ZFLAG+"折扣:"+ZKNULL);

input_table.appendRow();

https://www.sodocs.net/doc/8b12174173.html,("XSDDBH--"+XXDBH+"-");

input_table.setValue(XXDBH, "VBELN");//销售编号

https://www.sodocs.net/doc/8b12174173.html,("WAERS--"+WAERS+"-");

input_table.setValue(WAERS, "WAERS"); //货币类型

https://www.sodocs.net/doc/8b12174173.html,("POSNR--"+POSNR+"-");

input_table.setValue(POSNR, "POSNR");//项目编号

https://www.sodocs.net/doc/8b12174173.html,("KSCHL--"+KSCHL+"-");

input_table.setValue(KSCHL, "KSCHL");//折扣类型

https://www.sodocs.net/doc/8b12174173.html,("KBETR--"+KBETR+"-");

input_table.setValue(KBETR, "KBETR");//折扣金额

https://www.sodocs.net/doc/8b12174173.html,("ZFLAG--"+ZFLAG+"-");

input_table.setValue(ZFLAG, "ZFLAG");//修改类型

}

}

sapconnection.execute(function);

FLAG = (String) function.getExportParameterList().getValue("FLAG").toString();

MESSAGE = (String) function.getExportParameterList().getValue("MESSAGE").toString();

https://www.sodocs.net/doc/8b12174173.html,("FLAG=" +FLAG);

https://www.sodocs.net/doc/8b12174173.html,("MESSAGE=" + MESSAGE);

}catch(Exception e){

log.error(e);

}

}

return FLAG+"/"+MESSAGE;

}

//使用节点前或者节点后执行该方法方法名和参数不能修改

public String execute(RequestInfo request) {

SAPConnSAPConn = new SAPConn();

https://www.sodocs.net/doc/8b12174173.html,("do action on request:"+request.getRequestid());

String requestid = request.getRequestid();

RecordSetrs = new RecordSet();

String workflowid = request.getWorkflowid();

String maintable = "";

String sql = "select b.tablename from workflow_basea,workflow_bill b where a.formid = b.id and a.id = " + workflowid;

rs.executeSql(sql);

while(rs.next()){

maintable = rs.getString("tablename");

}

//查询流程使用的主表信息

String XSDDBH = ""; //销售订单号

String WAERS = ""; //货币类型

String POSNR = ""; //项目编号

String KSCHL = ""; //折扣类型

String KBETR = "0"; //折扣单价

String ZFLAG="";//编辑类型

String ERDAT = ""; // 货币类型销售单位

ERDAT = TimeUtil.getCurrentDateString();//当前日期

Property[] properties = request.getMainTableInfo().getProperty();// 获取表单主字段信息

for (int i = 0; i

String name = properties[i].getName().toUpperCase();//字段名

String value = Util.null2String(properties[i].getValue());//值

//销售订单号

if(name.equals("XSDDBH")){

XSDDBH = value;

}

https://www.sodocs.net/doc/8b12174173.html,("main:"+requestid+" "+name+" "+value);

}

String FLAG ="";

String MESSAGE="";

//https://www.sodocs.net/doc/8b12174173.html,("EPSTP-"+EPSTP);

try{

String PZZD="批准";

JCO.Function function = SAPConn.excuteBapi("ZXSRUT");//执行sap的写入接口

function.getImportParameterList().setValue(PZZD,"LV_VERSION");

JCO.Tableinput_table = null;

input_table = function.getTableParameterList().getTable("GT_XSRET");

// input_table.appendRow();

DetailTable[] detailtable = request.getDetailTableInfo().getDetailTable();// 获取明细表

if (detailtable.length> 0) {

for (int i = 0; i

DetailTabledt = detailtable[i];

Row[] s = dt.getRow();

for (int j = 0; j

Row r = s[j];

Cell c[] = r.getCell();

String ZKNULL="";

for (int k = 0; k

Cell c1 = c[k];

String name = c1.getName().toUpperCase();//字段名

String value = c1.getValue();//值

// WLMS 型号

// WLH 项目编号

// BZ 折扣

// SL 金额

// XQRQ 货币类型

//项目编号

if(name.equals("POSNRYC")){

POSNR = value;

}

//折扣类型

else if(name.equals("SQDJZK")){

KSCHL = GetLXDY(value);

ZKNULL=KSCHL;

}//折扣金额

else if(name.equals("SQDJJE")){

if(value.equals(""))

{

}

else

{

KBETR = value;

}

if(KBETR.equals("0"))

{

ZFLAG="D";

}

else

{

ZFLAG="U";

}

}else if(name.equals("HBLX")){

WAERS = value;

}

else

{

}

//else if(name.equals("CGZ")){

// EKGRP = value;

//}

https://www.sodocs.net/doc/8b12174173.html,("detail:"+requestid+" "+name+" "+value);

}

https://www.sodocs.net/doc/8b12174173.html,(XSDDBH+"---"+WAERS+"--"+POSNR+"---"+KSCHL+"--"+KBETR+"--"+ZFLAG+"完");

if(ZKNULL.equals(""))

{

continue;

}

input_table.appendRow();

https://www.sodocs.net/doc/8b12174173.html,("XSDDBH--"+XSDDBH+"-");

input_table.setValue(XSDDBH, "VBELN");//销售编号

https://www.sodocs.net/doc/8b12174173.html,("WAERS--"+WAERS+"-");

input_table.setValue(WAERS, "WAERS"); //货币类型

https://www.sodocs.net/doc/8b12174173.html,("POSNR--"+POSNR+"-");

input_table.setValue(POSNR, "POSNR");//项目编号

https://www.sodocs.net/doc/8b12174173.html,("KSCHL--"+KSCHL+"-");

input_table.setValue(KSCHL, "KSCHL");//折扣类型

https://www.sodocs.net/doc/8b12174173.html,("KBETR--"+KBETR+"-");

input_table.setValue(KBETR, "KBETR");//折扣金额

https://www.sodocs.net/doc/8b12174173.html,("ZFLAG--"+ZFLAG+"-");

input_table.setValue(ZFLAG, "ZFLAG");//修改类型

}

}

}

sapconnection.execute(function);

FLAG = (String) function.getExportParameterList().getValue("FLAG").toString();

MESSAGE = (String) function.getExportParameterList().getValue("MESSAGE").toString();

https://www.sodocs.net/doc/8b12174173.html,("FLAG=" +FLAG);

https://www.sodocs.net/doc/8b12174173.html,("MESSAGE=" + MESSAGE);

}catch(Exception e){

log.error(e);

}

return FLAG+"/"+MESSAGE;

}

//获取折扣信息以及价格

public String GetZK(String ZKHZZF)

{

try

{

String ZKLX="";

String ZKJE="";

String ZKZZFZH=ZKHZZF.replace(";",";");

String ZKHZ="";

if(ZKZZFZH.indexOf(";")>0)

{

String[] ZKSZ=ZKHZZF.split(";");//获取折扣的数量

for(int i=0;i

{

String ZKMX=ZKSZ[i].replace(":",":");

if(ZKMX.indexOf(":")>0)

{

String[] ZKMXSZ=ZKMX.split(":");

ZKLX=GetLXDY(ZKMXSZ[0]);//折扣类型

ZKJE=ZKMXSZ[1];//折扣金额

ZKHZ+=ZKLX+"-"+ZKJE;

}

}

}

return ZKHZ;

}catch(Exception e){

log.error(e);

return "";

}

}

//折扣中文与sap对应设置

public String GetLXDY(String ZWLX)

{

try{

String ZWHZ=ZWLX;

String SAPLX="";

if(ZWHZ.trim().equals("销售政策折扣"))

{

SAPLX="ZH01";

}else if(ZWHZ.trim().equals("股份公司折扣"))

{

SAPLX="ZH02";

}else if(ZWHZ.trim().equals("促销折扣"))

{

SAPLX="ZH03";

}else if(ZWHZ.trim().equals("其他折扣"))

{

SAPLX="ZH06";

}else if(ZWHZ.trim().equals("运费"))

{

SAPLX="ZH07";

}else if(ZWHZ.trim().equals("接待想调整"))

{

SAPLX="ZH08";

}else if(ZWHZ.trim().equals("装载机事业部折扣"))

{

SAPLX="ZZ01";

}else if(ZWHZ.trim().equals("重装工厂折扣"))

{

SAPLX="ZZ02";

}else if(ZWHZ.trim().equals("重装工厂运费折扣"))

{

SAPLX="ZZ03";

}else if(ZWHZ.trim().equals("配件折扣"))

{

SAPLX="ZZ05";

}

return SAPLX;

}

catch(Exception e)

{

return"";

}

}

}

相关主题