`
suipian1029
  • 浏览: 57652 次
  • 性别: Icon_minigender_1
  • 来自: 福州
社区版块
存档分类
最新评论

java与SAP集成回写单条记录模版(JCO3)

阅读更多

调用sap的公共类代码 
package com.tbsap.jcosap; 
import java.io.File; 
import java.io.FileOutputStream; 
import java.util.Properties; 
 
import com.sap.conn.jco.JCoDestination; 
import com.sap.conn.jco.JCoDestinationManager; 
import com.sap.conn.jco.JCoException; 
import com.sap.conn.jco.ext.DestinationDataProvider; 
 
public class SAPJCO { 
    static String ABAP_AS_POOLED = "ABAP_PUBLIC_600_SAPJCO_POOL";      
    private static void createDataFile()    
     
    {      
        Properties properties = new Properties(); 
        properties.setProperty(DestinationDataProvider.JCO_ASHOST, "sapIP"); 
        properties.setProperty(DestinationDataProvider.JCO_SYSNR,  "系统ID(00)"); 
        properties.setProperty(DestinationDataProvider.JCO_CLIENT, "客户端"); 
        properties.setProperty(DestinationDataProvider.JCO_USER,   "用户"); 
        properties.setProperty(DestinationDataProvider.JCO_PASSWD, "密码"); 
        properties.setProperty(DestinationDataProvider.JCO_LANG,   "预言"); 
        String name = ABAP_AS_POOLED; 
        String suffix =  "jcoDestination"; 
        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 JCoDestination getJcoConnection() throws JCoException{ 
         
        createDataFile(); 
        return JCoDestinationManager.getDestination(ABAP_AS_POOLED); 
    } 


单条记录回写sap标准函数的一种方式代码 
package com.topband.web.struts.action.supplier; 
 
import java.io.PrintWriter; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 
import org.apache.struts.action.ActionForward; 
import org.apache.struts.action.ActionMapping; 
import org.apache.struts.action.ActionForm; 
import org.apache.struts.actions.DispatchAction; 
import com.sap.conn.jco.AbapException; 
import com.sap.conn.jco.JCoDestination; 
import com.sap.conn.jco.JCoException; 
import com.sap.conn.jco.JCoFunction; 
import com.sap.conn.jco.JCoParameterList; 
import com.sap.conn.jco.JCoStructure; 
import com.sap.conn.jco.JCoTable; 
import com.tbsap.jcosap.SAPJCO; 
import javax.servlet.http.HttpSession; 
 
public class ItemAction extends DispatchAction{ 
 
    public ItemAction() { 
        super(); 
    } 
    public ActionForward ItemHXSAP(ActionMapping actionMapping, 
                                 ActionForm actionForm, 
                                 HttpServletRequest reuqest, 
                                 HttpServletResponse response) { 
         Supplier supplierbean = new Supplier(); 
         JCoDestination destination = null; 
         HttpSession session = reuqest.getSession(true); 
         Long userId = new Long(session.getAttribute("userId").toString()); //取当前用户的ID 
         Long orgId = new Long(session.getAttribute("orgId").toString()); //取当前用户的orgID 
         String itembo = reuqest.getParameter("itembo");   
         String itemdesc = reuqest.getParameter("itemdesc");   
         String wbitem = reuqest.getParameter("wbitem");     
         String dw = reuqest.getParameter("dw");  
         String checkwl = reuqest.getParameter("checkwl");  
         String wlz = reuqest.getParameter("wlz");  
         String msgs = ""; 
         String text = ""; 
         PrintWriter out = supplierbean.getWriterOut(response); 
         SAPJCO sapjco = new SAPJCO();  
            try 
            { 
                destination = sapjco.getJcoConnection(); 
                    JCoFunction function = destination.getRepository().getFunction("BAPI_MATERIAL_SAVEDATA"); 
                    JCoFunction function1 = destination.getRepository().getFunction("BAPI_TRANSACTION_COMMIT"); 
                if (function != null) 
                { 
                     
                    //JCoTable HEADDATA = function.getTableParameterList().getTable("HEADDATA"); 
                    //JCoTable CLIENTDATA = function.getTableParameterList().getTable("CLIENTDATA"); 
                    //JCoTable CLIENTDATAX = function.getTableParameterList().getTable("CLIENTDATAX");   
                    //String lifnr = function1.getExportParameterList().getString("LIFNR"); 
                    JCoTable MATERIALDESCRIPTION = function.getTableParameterList().getTable("MATERIALDESCRIPTION"); 
                    JCoTable UNITSOFMEASURE = function.getTableParameterList().getTable("UNITSOFMEASURE"); 
                    //JCoTable msg = function.getTableParameterList().getTable("RETURN");  
                 
                    JCoParameterList paramList = function.getImportParameterList(); 
                    JCoStructure HEADDATA =paramList.getStructure("HEADDATA"); 
                    JCoStructure CLIENTDATA =paramList.getStructure("CLIENTDATA"); 
                    JCoStructure CLIENTDATAX =paramList.getStructure("CLIENTDATAX"); 
                    //HEADDATA.appendRow(); 
                    System.out.println("A"+itembo); 
                    System.out.println("B"+itemdesc); 
                    System.out.println("C"+wbitem); 
                    System.out.println("D"+dw); 
                    System.out.println("E"+checkwl); 
                    if(itembo ==null || "null".equals(itembo)){ 
                        HEADDATA.setValue("MATERIAL", ""); 
                    }else{ 
                        String itembo1 = itembo.trim(); 
                        char[] itembo2 = itembo1.toCharArray(); 
                        HEADDATA.setValue("MATERIAL",itembo2);  
                    } 
                    HEADDATA.setValue("BASIC_VIEW","X"); 
                    HEADDATA.setValue("IND_SECTOR","M"); 
                    HEADDATA.setValue("MATL_TYPE","FERT"); 
                     
                    MATERIALDESCRIPTION.appendRow(); 
                    MATERIALDESCRIPTION.setValue("LANGU_ISO","ZH"); 
                    if(itemdesc ==null || "null".equals(itemdesc)){ 
                        MATERIALDESCRIPTION.setValue("MATL_DESC", ""); 
                    }else{ 
                        String itemdesc1 = itemdesc.trim(); 
                        char[] itemdesc2 = itemdesc1.toCharArray(); 
                        MATERIALDESCRIPTION.setValue("MATL_DESC",itemdesc2);  
                    } 
                    //CLIENTDATA.appendRow(); 
                    if(dw ==null || "null".equals(dw)){ 
                        CLIENTDATA.setValue("BASE_UOM", ""); 
                    }else{ 
                        String dw1 = dw.trim(); 
                        char[] dw2 = dw1.toCharArray(); 
                        CLIENTDATA.setValue("BASE_UOM",dw2);  
                    } 
                    if(wbitem ==null || "null".equals(wbitem)){ 
                        CLIENTDATA.setValue("EXTMATLGRP", ""); 
                    }else{ 
                        String wbitem1 = wbitem.trim(); 
                        char[] wbitem2 = wbitem1.toCharArray(); 
                        CLIENTDATA.setValue("EXTMATLGRP",wbitem2);  
                    } 
                    if(checkwl ==null || "null".equals(checkwl)){ 
                        CLIENTDATA.setValue("PROD_MEMO", ""); 
                    }else{ 
                        String checkwl1 = checkwl.trim(); 
                        char[] checkwl12 = checkwl1.toCharArray(); 
                        CLIENTDATA.setValue("PROD_MEMO",checkwl12);  
                    } 
                     
                    if(wlz ==null || "null".equals(wlz)){ 
                        CLIENTDATA.setValue("MATL_GROUP", ""); 
                    }else{ 
                        String wlz1 = wlz.trim(); 
                        char[] wlz2 = wlz1.toCharArray(); 
                        CLIENTDATA.setValue("MATL_GROUP",wlz2);  
                    } 
                     
                    if(wlz ==null || "null".equals(wlz)){ 
                        CLIENTDATA.setValue("MATL_GROUP", ""); 
                    }else{ 
                        String wlz1 = wlz.trim(); 
                        char[] wlz2 = wlz1.toCharArray(); 
                        CLIENTDATA.setValue("MATL_GROUP",wlz2);  
                    } 
                    //CLIENTDATAX.appendRow(); 
                    CLIENTDATA.setValue("BASIC_MATL","X"); 
                    CLIENTDATAX.setValue("BASIC_MATL","X"); 
                    CLIENTDATAX.setValue("MATL_GROUP","X"); 
                    CLIENTDATAX.setValue("BASE_UOM","X"); 
                    CLIENTDATAX.setValue("PROD_MEMO","X"); 
                    CLIENTDATAX.setValue("EXTMATLGRP","X"); 
                    UNITSOFMEASURE.appendRow(); 
                    if(dw ==null || "null".equals(dw)){ 
                        UNITSOFMEASURE.setValue("ALT_UNIT", ""); 
                    }else{ 
                        String dw1 = dw.trim(); 
                        char[] dw2 = dw1.toCharArray(); 
                        UNITSOFMEASURE.setValue("ALT_UNIT",dw2); 
                    } 
                    function.execute(destination); 
                    JCoStructure msg = function.getExportParameterList().getStructure("RETURN"); 
                    //接受SAP 传出参数 
                     //for (int i = 0; i < msg.getNumRows(); ++i){ 
                        // msg.setRow(i); 
                         msgs = msg.getString("TYPE"); 
                         text = msg.getString("MESSAGE"); 
                         System.out.println("值"+msgs);  
                            System.out.println("值2"+text); 
                         if(msgs=="S" || "S".equals(msgs)){ 
                                JCoParameterList paramList1 = function1.getImportParameterList(); 
                                paramList1.setValue("WAIT", "X"); 
                             function1.execute(destination); 
                         } 
                    // } 
                         out.print(msgs.concat(",").concat(text));  //反馈描述信息 
                } 
        }catch(AbapException e)      
        {     
            destination = null; 
         } catch (JCoException e) { 
             destination = null; 
            e.printStackTrace(); 
        }finally{ 
            destination = null; 
        } 
 
        return null; 
        
    } 
     
 



单个回写sap自己写的函数模版代码 
package com.topband.web.struts.action.supplier; 
 
import java.io.PrintWriter; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 
import org.apache.struts.action.ActionForward; 
import org.apache.struts.action.ActionMapping; 
import org.apache.struts.action.ActionForm; 
import org.apache.struts.actions.DispatchAction; 
import com.sap.conn.jco.AbapException; 
import com.sap.conn.jco.JCoDestination; 
import com.sap.conn.jco.JCoException; 
import com.sap.conn.jco.JCoFunction; 
import com.sap.conn.jco.JCoParameterList; 
import com.sap.conn.jco.JCoTable; 
import com.tbsap.jcosap.SAPJCO; 
import com.topband.supplier.model.SupplierBean; 
import javax.servlet.http.HttpSession; 
 
public class zhugx01 extends DispatchAction{ 
    public zhugx01() { 
        super(); 
    } 
    public ActionForward LSHXSAP(ActionMapping actionMapping, 
                                 ActionForm actionForm, 
                                 HttpServletRequest reuqest, 
                                 HttpServletResponse response) { 
          Supplier supplierbean = new Supplier(); 
         JCoDestination destination = null; 
         HttpSession session = reuqest.getSession(true); 
         Long userId = new Long(session.getAttribute("userId").toString()); //取当前用户的ID 
         Long orgId = new Long(session.getAttribute("orgId").toString()); //取当前用户的orgID 
         String workid = reuqest.getParameter("id");  //流程记录ID 
         int type = Integer.parseInt(reuqest.getParameter("type"));        //类型 
         String zhz = reuqest.getParameter("zhz");     //账户组 
         String gysbh = reuqest.getParameter("gysbh");  //供应商编号 
         String sylx = reuqest.getParameter("sylx");  //使用类型 
         String suppliertype = reuqest.getParameter("supplier");  //使用类型 
         String msgs = ""; 
         String text = ""; 
         String cczzid = ""; 
         String dj = ""; 
         String zt = ""; 
          PrintWriter out = supplierbean.getWriterOut(response); 
          SAPJCO sapjco = new SAPJCO();  
            try 
            { 
                destination = sapjco.getJcoConnection(); 
            if(suppliertype == "L" || "L".equals(suppliertype)){ 
                SupplierBean lsbean = (SupplierBean)supplierbean.GetLSupplier(workid); 
                int number = supplierbean.SelectLsfz(gysbh,lsbean.getCgzz()); 
                if(lsbean.equals("null") || lsbean ==null){ 
                    out.print("E,没有找到信息记录不能回写SAP");  //反馈描述信息 
                }else{ 
                 if(zhz == "Z001" || "Z001".equals(zhz) || zhz == "Z003" || "Z003".equals(zhz)){ 
                        JCoFunction function1 = destination.getRepository().getFunction("ZMM_VENDOR_YC"); 
                         
                        JCoTable supplier1 = function1.getTableParameterList().getTable("ZTEMP_VENDOR"); 
                        JCoTable msg1 = function1.getTableParameterList().getTable("ZMSGTAB1"); 
                        JCoParameterList paramList = function1.getImportParameterList(); 
                        supplier1.appendRow(); 
                        zt = "原厂供应商"; 
                        if(type == 0){ 
                            //新建 
                            dj = "0"; 
                            paramList.setValue("ZBZ","I"); 
                        }else if(type == 1 && (sylx == "" || "".equals(sylx) || sylx == "0" || "0".equals(sylx))){ 
                            //修改 
                            dj = ""; 
                            paramList.setValue("ZBZ","U"); 
                        }else if(type == 1 && (sylx == "D" || "D".equals(sylx))){ 
                            //修改冻结 
                            dj = "D"; 
                            paramList.setValue("ZBZ","D"); 
                        }else if(type == 1 && (sylx == "J" || "J".equals(sylx))){ 
                            //修改解冻 
                            dj = "J"; 
                            paramList.setValue("ZBZ","J"); 
                        } 
                         
                        if(lsbean.getGysbh() ==null || "null".equals(lsbean.getGysbh()) ){ 
                            supplier1.setValue("LIFNR", ""); 
                        }else{ 
                            String LIFNR1 = lsbean.getGysbh().trim(); 
                            char[] LIFNR = LIFNR1.toCharArray(); 
                            supplier1.setValue("LIFNR",LIFNR);  
                        } 
                         
                        if(lsbean.getCgzz() ==null || "null".equals(lsbean.getCgzz()) ){ 
                            supplier1.setValue("ZEKORG", ""); 
                        }else{ 
                             cczzid = supplierbean.Selectcgzz(lsbean.getCgzz()); 
                            System.out.println("采购组织ID"+cczzid); 
                             
                            char[] cgzz = cczzid.toCharArray(); 
                            supplier1.setValue("ZEKORG",cgzz);  
                        } 
                        if(lsbean.getSkzh() ==null || "null".equals(lsbean.getSkzh())){ 
                            supplier1.setValue("ZYHZH", ""); 
                        }else{ 
                            String ZYHZH1 = lsbean.getSkzh().trim(); 
                            char[] ZYHZH = ZYHZH1.toCharArray(); 
                            supplier1.setValue("ZYHZH",ZYHZH);  
                        } 
                         
                        function1.execute(destination); 
                        String lifnr = function1.getExportParameterList().getString("LIFNR"); 
                     
                         for (int i = 0; i < msg1.getNumRows(); ++i){ 
                             msg1.setRow(i); 
                             msgs = msg1.getString("MSGTYP1"); 
                             text = msg1.getString("TEXT"); 
                                System.out.println("值"+msgs);  
                                System.out.println("值2"+text); 
                                 
                         } 
                          
                         if(msgs=="S" || "S".equals(msgs)){ 
                              
                                out.print(msgs.concat(",").concat(text));  //反馈描述信息 
                             if(number >0){ 
                                 supplierbean.UpdateLsfz(lsbean,dj,zt,cczzid); 
                             }else{ 
                                 supplierbean.AddLsfz(lsbean,lifnr,userId,orgId,dj,zt,cczzid,null); 
                             } 
                         }else{ 
                             out.print(msgs.concat(",").concat(text));  //反馈描述信息 
                         } 
                    }  
                } 
            } 
        }catch(AbapException e)      
        {     
            destination = null; 
         } catch (JCoException e) { 
             destination = null; 
            e.printStackTrace(); 
        }finally{ 
            destination = null; 
        } 
        return null; 
    } 
     


分享到:
评论

相关推荐

    JAVA链接SAP相关jar包(sapjco3.jar、sapjco3.dll、libsapjco3.so)

    首先,sapjco3.jar是SAP Java Connector的核心库,它提供了Java接口,使得Java程序能够与SAP系统进行通信。这个库包含了所有的Java类和接口,开发者可以通过这些API来创建连接、执行RFC(远程功能调用)和BAPI...

    java连接sap接口包sapjco3 window36/64

    java连接sap系统需要通过sap javaconnect来连接,对于sapjco3.jar系列文件有32位与64位之分。 a)确定本机使用JDK版本,一般均为32位。 b)将相对应位数的sapjco3.dll文件拷贝至system32。 c)将相对应位数sapjco.jar...

    java和sap集成jco包

    1. **JCO接口**:SAP JCo(Java Connector Architecture)是SAP NetWeaver系统提供的一套API,允许Java应用程序与SAP R/3系统无缝集成。它提供了客户端和服务器端的连接、数据传输以及事务管理等功能。 2. **组件...

    SAP2021年6月版本sapjco3.1

    SAP是一种全球领先的业务软件解决方案,它为企业提供...对于开发与SAP系统集成的Java应用,理解和掌握SAP JCo的使用至关重要,这包括对`sapjco3.jar`和`sapjco3.dll`的理解,以及如何在不同环境下正确配置和调用它们。

    sapjco3.dll结合sapjco3.jar包下载

    1.sapjco3.dll 需要与 sapjco3.jar 在同一目录 2.设置系统环境变量,将sapjco3所在目录加入系统环境变量 3.根据自己的操作系统版本选择对应的sapjco3包 32位系统 例如: 新建环境变量 变量名: JAVA_SAPJCO 变量...

    java连接sap接口包sapjco3

    java连接sap系统需要通过sap javaconnect来连接,对于sapjco3.jar系列文件有32位与64位之分。 a)确定本机使用JDK版本,一般均为32位。 b)将相对应位数的sapjco3.dll文件拷贝至system32。 c)将相对应位数sapjco.jar...

    SAP Java JCo 3.1.3 Linux + Windows 64bit下载

    总结起来,SAP Java Connector 3.1.3是Java开发者与SAP系统交互的重要工具,通过提供的`sapjco3.dll`、`sapjco3.jar`和`libsapjco3.so`文件,能够在Linux和Windows 64位环境下构建和运行与SAP集成的应用程序。...

    sapjco3 jar包

    1.sapjco3.dll 需要与 sapjco3.jar 在同一目录 2.设置系统环境变量,将sapjco3所在目录加入系统环境变量 例如: 新建环境变量 变量名: JAVA_SAPJCO 变量值: E:\sapjco3\sapjco3-win32 将新建的 JAVA_SAPJCO 环境...

    sapjco3.jar下载

    SAP JCo (Java Connector) 是 SAP 提供的一款用于 Java 应用程序与 SAP 系统之间集成的重要组件。在本文中,我们将深入探讨 SAP JCo3,即 SAP Java Connector 的第三版本,以及如何处理其可能遇到的问题。 首先,`...

    sapjco30/sapjco3.dll/sapjco3.jar SAP官网2017/7/18更新版本

    SAP JCo (Java Connector) 是一款用于连接Java应用程序与SAP系统的关键组件,它提供了在Java环境中访问SAP R/3系统或者SAP NetWeaver应用服务器的能力。"sapjco30"指的是SAP JCo的第三版,这个版本对应于JCo 3.0,是...

    java与sap交互 jco包

    Java与SAP交互是企业级应用集成中的常见需求,JCO(Java Connector)是SAP提供的用于Java应用程序与SAP系统通信的接口。本篇将详细介绍如何利用JCO包进行Java与SAP的交互,以及如何处理jar包和dll文件。 首先,JCO...

    JAVA 调用SAP端接口的相关包(sapjco3.jar,sapjco3.dll,sapjcorfc.dll)

    在Java开发中,有时我们需要与SAP系统进行交互,实现数据的同步或者业务流程的集成。在这种场景下,SAP提供了Java Connector (简称JCo),它是一个用于在Java应用程序和SAP系统之间建立通信的库。JCo允许Java开发者...

    Java连接SAP系统所用的JCo连接池的配置和使用

    "Java连接SAP系统所用的JCo连接池的配置和使用" Java连接SAP系统所用的JCo连接池的配置和使用是指在Java应用程序中使用JCo连接池来连接SAP R3系统的技术。JCo(Java Connector)是SAP提供的一种Java API,用于连接...

    sapjco3.dll sapjco3.jar 版本 7210,1120,28,55042 64位.zip

    标题中的"SAPJCO3.dll SAPJCO3.jar"指的是SAP Java Connector 3的动态链接库(.dll)和Java档案(.jar),这是连接SAP系统与Java应用程序的关键组件。版本号"7210,1120,28,55042"代表了该软件的具体更新迭代,其中...

    sapjco3.dll

    windows环境设置1.sapjco3.dll需要与sapjco3.jar在同一目录2.设置系统环境变量,将sapjco3所在目录加入系统环境变量例如:新建环境变量变量名:JAVA_SAPJCO变量值:E:\ sapjco3 \ sapjco3- win32将新建的JAVA_SAP...

    SAP官网最新linux、windows版 sapjco3.jar

    总之,SAP JCo3是Java开发者与SAP系统集成的重要工具,它简化了Java应用与SAP的接口开发,提供了高效、稳定的数据交换机制。通过使用`sapjco3.jar`和对应的本地库文件,开发者可以轻松地在Linux或Windows环境中实现...

    sapjco3 32位64位.dll+jar

    windows 环境设置 1.sapjco3.dll 需要与 sapjco3.jar 在同一目录 2.设置系统环境变量,将sapjco3所在目录加入系统环境变量 例如: 新建环境变量 变量名: JAVA_SAPJCO 变量值: E:\sapjco3\sapjco3-win32 将新建的 JAVA_...

    sapjco3最新版

    SAP JCo3,全称为SAP Java Connector 3.0,是SAP公司提供的一种用于Java应用程序与SAP R/3系统之间进行双向通信的中间件技术。它基于Java平台,为开发者提供了丰富的API,使得Java应用能够无缝集成到SAP系统中,执行...

    JAVA对接SAP接口使用sapjco3.dll跟jar文件

    本文将详细介绍如何使用SAP JCo(Java Connector)库,特别是通过`sapjco3.dll`和`jar`文件来实现JAVA与SAP接口的对接。 首先,SAP JCo是一个Java API,它允许Java应用程序与SAP系统进行通信。JCo提供了两种主要的...

Global site tag (gtag.js) - Google Analytics