java与SAP集成批批量处理模版(JCO3)

java
Java批量获取sap数据代码 
package com.topband.web.struts.action.supplier; 
 
 
import java.util.ArrayList; 
import java.util.List; 
import org.quartz.Job; 
import org.quartz.JobExecutionContext; 
import org.quartz.JobExecutionException; 
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 com.topband.web.struts.action.supplier.SAPJobSupplier; 
 
public class zhugx01 implements Job{ 
     public zhugx01() { 
            super(); 
        } 
     /* 
      * SAP定时更新临时供应商记录 
      */ 
    public void execute(JobExecutionContext context)  throws JobExecutionException { 
          SAPJobSupplier supplierlsbean = new SAPJobSupplier(); 
         JCoDestination destination = null; 
         SAPJCO sapjco = new SAPJCO();  
         
        try 
        { 
            destination = sapjco.getJcoConnection(); 
                        JCoFunction function = destination.getRepository().getFunction("ZMM_VENDOR_CQ"); 
                        if (function != null) 
                        { 
                            JCoTable saplssupplier = function.getTableParameterList().getTable("ZVENDOR_STRUC"); 
                            JCoParameterList paramList = function.getImportParameterList(); 
                            paramList.setValue("ZBZ","1"); 
                            function.execute(destination); 
                             List  lslist= new ArrayList(); 
                             System.out.println("临时供应商条数"+saplssupplier.getNumRows()); 
                             for (int i = 0; i < saplssupplier.getNumRows(); ++i) { 
                                 saplssupplier.setRow(i); 
                                 SupplierBean lsbean= new SupplierBean(); 
                                 lsbean.setGysbh(saplssupplier.getString("LIFNR"));  //供应商编号 
                                 lsbean.setName(saplssupplier.getString("NAME"));   //公司名称 
                                 lsbean.setGyszt("临时供应商"); 
                                 lslist.add(lsbean); 
                             } 
                             supplierlsbean.UpdateSupplierfz(lslist,null,null); 
                        } 
        }catch(AbapException e)      
        {     
            destination = null; 
         } catch (JCoException e) { 
             destination = null; 
            e.printStackTrace(); 
        }finally{ 
            destination = null; 
        } 
 
    } 


单个与批量回写sap模版代码 
package com.topband.web.struts.action.Recruitment; 
 
import java.io.PrintWriter; 
import java.sql.Connection; 
import java.sql.Statement; 
import java.util.List; 
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.JCoTable; 
import com.tbsap.jcosap.SAPJCO; 
import com.topband.recruitment.model.Family; 
import com.topband.recruitment.model.LYXX; 
import com.topband.recruitment.model.ZGJL; 
import com.whir.common.util.DataSourceBase; 
 
public class zhugx extends DispatchAction{ 
     
     DataSourceBase dsb = new DataSourceBase(); 
         Connection conn = null; 
         Statement stmt = null; 
         String sql =null; 
         java.sql.ResultSet rs =null;   
         LYWK ly = new LYWK(); 
 
    public zhugx() { 
        super(); 
    } 
    public ActionForward HXSAP(ActionMapping actionMapping, 
                                 ActionForm actionForm, 
                                 HttpServletRequest reuqest, 
                                 HttpServletResponse response) { 
         JCoDestination destination = null; 
        String workid = reuqest.getParameter("lid"); 
        String adr = reuqest.getParameter("adr"); 
        String msgs = ""; 
        String text = ""; 
        String id = ""; 
        LYXX lyx = (LYXX)ly.GetLYxx(workid); 
        List jtlist = ly.Getjtlist(workid); 
        List gzlist = ly.Getgzlist(workid); 
         SAPJCO sapjco = new SAPJCO();  
             
            try 
            { 
                destination = sapjco.getJcoConnection(); 
            JCoFunction function = destination.getRepository().getFunction("ZHR_RZ_01"); 
            if (function != null) 
            { 
                JCoTable lysap = function.getTableParameterList().getTable("ZZHR_RZ"); 
                JCoTable gz = function.getTableParameterList().getTable("ZZHR_GZ"); 
                JCoTable jt = function.getTableParameterList().getTable("ZZHR_JT"); 
                JCoTable msg = function.getTableParameterList().getTable("ZMSGTAB"); 
                lysap.appendRow(); 
                if(lyx.getNAME() ==null){ 
                    lysap.setValue("NACHN",""); 
                }else{ 
                    char[] name = lyx.getNAME().toCharArray(); 
                    lysap.setValue("NACHN",name); 
                } 
                if(lyx.getZY() ==null){ 
                    lysap.setValue("SPEC_NAME",""); 
                }else{ 
                    char[] zy = lyx.getZY().toCharArray(); 
                    lysap.setValue("SPEC_NAME",zy);  
                } 
                 
                for(int i =0;i<jtlist.size();i++){ 
                    Family jtxx= (Family)jtlist.get(i); 
                    jt.appendRow(); 
                    jt.setRow(i); 
                    if(jtxx.getLxdz() ==null){ 
                        jt.setValue("ADDRESS",""); 
                    }else{ 
                        char[] addre = jtxx.getLxdz().toCharArray(); 
                        jt.setValue("ADDRESS", addre); 
                    } 
                    if(jtxx.getLxtel() ==null){ 
                        jt.setValue("ZTELEPOHNE",""); 
                    }else{ 
                        char[] tel = jtxx.getLxtel().toCharArray(); 
                        jt.setValue("ZTELEPOHNE", tel); 
                    } 
                } 
                 
                for(int j =0;j<gzlist.size();j++){ 
                    ZGJL gzxx= (ZGJL)gzlist.get(j); 
                    gz.appendRow(); 
                    gz.setRow(j); 
                    if(gzxx.getKssj() ==null){ 
                        gz.setValue("BEGDA2",""); 
                    }else{ 
                        char[] kssj = gzxx.getKssj().toCharArray(); 
                        gz.setValue("BEGDA2", kssj); 
                    } 
                    if(gzxx.getJssj() ==null){ 
                        gz.setValue("ENDDA2",""); 
                    }else{ 
                        char[] jssj = gzxx.getJssj().toCharArray(); 
                        gz.setValue("ENDDA2", jssj); 
                    } 
                } 
                function.execute(destination); 
                 for (int i = 0; i < msg.getNumRows(); ++i){ 
                     msg.setRow(i); 
                     msgs = msg.getString("MSGTYP"); 
                     text = msg.getString("TEXT"); 
                     id = msg.getString("PERNR1"); 
                        System.out.println("值3"+id);  
                 } 
            } 
        }catch(AbapException e)      
        {     
            destination = null; 
         } catch (JCoException e) { 
             destination = null; 
            e.printStackTrace(); 
        }finally{ 
            destination = null; 
        } 
        PrintWriter out = ly.getWriterOut(response); 
        out.print(msgs.concat("@".concat(text)).concat("%".concat(id)));  // S/成功   E 失败  
        return null; 
           
        
    } 
     

你可能感兴趣的:(java)