oa与sap接口java后台代码编写说明window版本.docx
- 文档编号:3787239
- 上传时间:2022-11-25
- 格式:DOCX
- 页数:22
- 大小:21.84KB
oa与sap接口java后台代码编写说明window版本.docx
《oa与sap接口java后台代码编写说明window版本.docx》由会员分享,可在线阅读,更多相关《oa与sap接口java后台代码编写说明window版本.docx(22页珍藏版)》请在冰豆网上搜索。
oa与sap接口java后台代码编写说明window版本
oa与sap接口后台java接口说明
(window版本)
后台java处理页面分为三个sapconn.javasap连接javaXSJGSPAction.java数据获取的javaXSJGSPHXAction.java数据回写的java
Sapconn.java编写说明
内容以及编写说明(该类不需要修改)
packageweaver.interfaces.workflow.action;
importjavax.swing.JOptionPane;
importcom.sap.mw.jco.*;
importweaver.general.BaseBean;
publicclassSAPConnextendsjavax.swing.JFrame{
finalstaticlongserialVersionUID=90;
finalstaticStringPOOL_NAME="Pool";
privatestaticJCO.ClientmConnection=null;
privatestaticBaseBeanbb=newBaseBean();
privatestaticStringsapclient="";
privatestaticStringuserid="";
privatestaticStringpassword="";
privatestaticStringhostname="";
privatestaticStringsystemnumber="";
privatestaticStringLanguage="";
/*
*初始化连接
*/
publicvoidSAPConn(){
}
/*
*初始化连接
*/
privatevoidinit(){
try{//读取配置文件信息
bb.writeLog("-------------SAPClientConnectsStart----------------");
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.Poolpool=JCO.getClientPoolManager().getPool(POOL_NAME);
if(pool==null){
JCO.addClientPool(POOL_NAME,//poolname
100,//maximumnumberofconnections
sapclient,
userid,
password,
Language,
hostname,
systemnumber);
}
setConnection(JCO.getClient(POOL_NAME));//获取连接
bb.writeLog("getconnectionsuccess");
}catch(Exceptione){
bb.writeLog("getconnectionerror:
"+e);
}
}
/*
*释放连接
*/
publicvoidreleaseC(){
if(mConnection!
=null)
JCO.releaseClient(mConnection);
}
/*
*获取连接
*/
publicJCO.ClientgetConnection(){
if(mConnection==null)
{
init();
}
returnmConnection;
}
/*
*设置连接
*/
publicvoidsetConnection(JCO.Clientconn){
mConnection=conn;
}
/*
*执行Bapi
*/
publicJCO.FunctionexcuteBapi(Strings){
System.out.println("GETINTOFunctionBapi!
");
SAPConnsapconn=newSAPConn();
JCO.Clientsapconnection=sapconn.getConnection();
JCO.RepositorymRepository;
JCO.FunctionjcoFunction=null;
System.out.println("sapconnection=="+sapconnection);
if(sapconnection==null)returnjcoFunction;
try{
mRepository=newJCO.Repository("sap",sapconnection);
System.out.println("mRepository=="+mRepository);
IFunctionTemplateft=mRepository.getFunctionTemplate(s);
jcoFunction=newJCO.Function(ft);
System.out.println("excueteBapiSuccess");
returnjcoFunction;
}catch(Exceptione){
System.out.println(e);
JOptionPane.showMessageDialog(null,e.getMessage(),"错误信息",0);
returnnull;
}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系统文件
publicclassXSJGSPAction{
//生成jco对象对sap进行操作的对象
privateJCO.Clientsapconnection=newSAPConn().getConnection();
privateintcursorindex=-1;
privateintdataconts=0;
privateJCO.Tabledatas=null;
/*
*初始化
*/
publicvoidXSJGSPAction(){
}
/*
*执行Bapi不需要修改
*/
publicJCO.FunctionexcuteBapi(Strings){
System.out.println("GETINTOFunctionBapi!
");
SAPConnsapconn=newSAPConn();//生成sap对象
JCO.Clientsapconnection=sapconn.getConnection();//获取连接
JCO.RepositorymRepository;
JCO.FunctionjcoFunction=null;//生成function对象
System.out.println("sapconnection=="+sapconnection);
if(sapconnection==null)returnjcoFunction;
try{
mRepository=newJCO.Repository("sap",sapconnection);
System.out.println("mRepository=="+mRepository);
IFunctionTemplateft=mRepository.getFunctionTemplate(s);
jcoFunction=newJCO.Function(ft);
System.out.println("excueteBapiSuccess");
returnjcoFunction;
}catch(Exceptione){
System.out.println(e);
JOptionPane.showMessageDialog(null,e.getMessage(),"错误信息",0);
returnnull;
}finally{
}
}
//编写数据获取类
publicListGetexecute(Stringlv_vbeln){
Listlist=newArrayList();
try{
cursorindex=-1;
dataconts=0;
datas=null;
Mapmmap=null;
Mapdmap=null;
Listmlist=newArrayList();//存放主表数据
Listdlist=newArrayList();//存放明细表数据
//functionname执行sap提供的接口参数为接口名称
JCO.Functionbapi=excuteBapi("ZXSDDSPJK");//ZFUN_OA_CREATEPRZXSDDSPJKzxsddspjk
//inputvalue
StringLV_VBELN=lv_vbeln;
//设置输入参数
bapi.getImportParameterList().setValue(LV_VBELN,"LV_VBELN");//lv_vbeln
sapconnection.execute(bapi);//执行接口
//datas=bapi.getTableParameterList().getTable("SPXM");
StringMESSAGEFX=(String)bapi.getExportParameterList().getValue("MESSAGE").toString();//获取接口返回值
System.out.println(">>>>>>>>>>>>>>>>>>MESSAGEFX="+MESSAGEFX);
Tablecodes=bapi.getTableParameterList().getTable("SPBT");//获取接口返回的表数据
//intcellrow=0;
//cellrow=codes.getgetNumRows();
//String[]maintable=newString[cellrow];
//获取主表信息保存在mlist中
for(inti=0;i { codes.setRow(i); mmap=newHashMap(); ///获取主表中的数据存放如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中 Tablecodesmx=bapi.getTableParameterList().getTable("SPXM"); System.out.println("-------------"+codesmx.getNumRows()); for(inti=0;i { codesmx.setRow(i); dmap=newHashMap(); //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(Exceptione){ System.out.println(e); } returnlist; } } 回写类XSJGSPHXAction.java 内容以及编写说明 packageweaver.interfaces.workflow.action; importjava.awt.List; importjava.awt.peer.LightweightPeer; mons.logging.Log; 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; publicclassXSJGSPHXActionimplementsAction{ //生成sapconn对象 privateJCO.Clientsapconnection=newSAPConn().getConnection(); privateLoglog=LogFactory.getLog(XSJGSPHXAction.class.getName()); publicLoggetLog(){ returnlog; } publicvoidsetLog(Loglog){ this.log=log; } //回写执行的方法自己编写的方法 publicStringexecutexr(Stringrequeststring) { StringFLAG="E"; StringMESSAGE=""; Stringrequesthq=requeststring; if(requesthq.indexOf("$")>0) { SAPConnSAPConn=newSAPConn(); String[]liststr=requesthq.split("\\$");//获取主表明细表数据 if(liststr.length<2) { //System.out.println(liststr[0]); return"E/数据有误vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv! "; } Stringmliststr=liststr[0];//主表信息数据以;分割字段格式为: key: value Stringdliststr=liststr[1];//明细表多条明细以~分割字段和主表相同 //获取主表信息 String[]mzdliststr=mliststr.split(";");//获取主表明细表数据 StringRequestid=""; StringWorkflowid=""; StringXXDBH=""; //System.out.println("suoyou"+requesthq+"主表信息------"+mliststr+"mx------"+dliststr); for(inti=0;i { //获取所有主表信息格式为key: value Stringkeyvalue=mzdliststr[i]; //System.out.println("主表信息------"+keyvalue); if(keyvalue.indexOf(": ")>0) { System.out.println("------"+keyvalue); String[]keyvaluezh=keyvalue.split(": "); if(keyvaluezh.length<2) { continue; } Stringkey=keyvaluezh[0].toUpperCase(); Stringvalue=keyvaluezh[1]; if(key.equals("requestidValue")) { Requestid=value; }elseif(key.equals("workflowidValue")) { Workflowid=value; }elseif(key.equals("VBELN")) { XXDBH=value; } } } try { StringPZZD="批准"; JCO.Functionfunction=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_"
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- oa sap 接口 java 后台 代码 编写 说明 window 版本
![提示](https://static.bdocx.com/images/bang_tan.gif)