SAP,JAVA环境下RFC调用示例(3)

public void DelInfo(Database db,String pobh)
  {
  try
  {
  
                View view=db.getView("v_key_tx");
    DocumentCollection dc =view.getAllDocumentsByKey(pobh, true);
    if (dc.getCount()>0){
     dc.removeAll(true);
     }
   }
    catch(Exception e)
  {
         System.out.println(e.getMessage());
       }
  }
 
 //用关键字返回文档
     public Document ReturnTypeDoc(Database db,String Key,String vname) throws Exception{
 
      Document DateDoc = null;
          View SearchSubView = null;
          Vector SearchKey = new Vector();
 
  try{
   SearchSubView = db.getView(vname);
   SearchSubView.refresh();
   SearchKey.addElement(Key);
  
   DateDoc = SearchSubView.getDocumentByKey(SearchKey,true);
  
               if (SearchSubView != null){
       SearchSubView.recycle();
               }
                   SearchKey = null;
  
   if (DateDoc != null){
        return DateDoc;
   }else{
    return null;
   }
  
 
 
         }catch(Exception e) {
            e.printStackTrace();
            return null;
         }
 }
 
  public Document getDoucumet(Database CurDb, Vector SapSearchKey, Session session)throws Exception{
 
               Database Configdb = null;
               Document SapConfigDoc = null;
               View ConView = null;
               try{         
                  String DbPath;    
                  DbPath = CurDb.getFilePath();
                  DbPath = DbPath.substring(0,DbPath.length() - CurDb.getFileName().length());
                  DbPath = DbPath + configDbName;
               
                  //读取配置数据库
                  Configdb = session.getDatabase(CurDb.getServer(),DbPath,true);
                  //读取视图
                  ConView = Configdb.getView(viewName);
                  //读取配置文档
                  SapConfigDoc = ConView.getDocumentByKey(SapSearchKey, false);     
                  return SapConfigDoc;
                }catch(Exception e) {
                  e.printStackTrace();
                return null;
                }
     }
   
   
    //这个方法将字符串line中的子串oldString全部替换为newString
    public static final String replace( String line, String oldString, String newString )
    {
        if (line == null) {
            return null;
        }
        int i=0;
        if ( ( i=line.indexOf( oldString, i ) ) >= 0 ) {
            char [] line2 = line.toCharArray();
            char [] newString2 = newString.toCharArray();
            int oLength = oldString.length();
            StringBuffer buf = new StringBuffer(line2.length);
            buf.append(line2, 0, i).append(newString2);
            i += oLength;
            int j = i;
            while( ( i=line.indexOf( oldString, i ) ) > 0 ) {
                buf.append(line2, j, i-j).append(newString2);
                i += oLength;
                j = i;
            }
            buf.append(line2, j, line2.length - j);
            return buf.toString();
        }
        return line;
    }
  
  
     public void creatlog(Database db, Session session ,Document doc ,AgentContext agentContext,DateTime writetime,String tcode,String bh,String pzh,String memo,String action)
  {
  try
  { //---------------------------------------------------------------------
   ///////////////在OA中记录开始写SAP的日志start
    String logDbPath = "oadata/write_sap_log.nsf";
                Database saplogdb = session.getDatabase(db.getServer(),logDbPath,true);
                if (saplogdb.isOpen()){}else{
                   saplogdb.open();
                }
                if (saplogdb!=null){
             
      //String REQUESTNUMBER = "";
                   
      // REQUESTNUMBER = doc.getItemValueString("REQUESTNUMBER");
    
                   Document logdoc = saplogdb.createDocument();
                      logdoc.replaceItemValue("Form", "f_or_saplog"); 
                       logdoc.replaceItemValue("TCODE",tcode);      /////记录tcode
      logdoc.replaceItemValue("DOCUNID",  doc.getUniversalID());  //当前文档UNID
          logdoc.replaceItemValue("OADbName", db.getFileName());  //当前库
          logdoc.replaceItemValue("RequestNum",bh);  //文档REQUESTNUMBER
          logdoc.replaceItemValue("dealaction",action);  //处理动作
          logdoc.replaceItemValue("dealuser",doc.getItemValueString("SelfName").trim());  //记录处理人
          logdoc.replaceItemValue("dealuserID",doc.getItemValueString("SelfWorkID").trim());  //记录处理人ID
      logdoc.replaceItemValue("dealuserCom", doc.getItemValueString("SelfcompanyShortName").trim());  //处理人所在公司
          logdoc.replaceItemValue("dealuserDep", doc.getItemValueString("SelfdepartmentShortName").trim());  //处理人所在部门   
      logdoc.replaceItemValue("dealDate",writetime.getDateOnly());              //处理日期       
                      logdoc.replaceItemValue("dealtime",writetime.getTimeOnly());              //处理时间
                          logdoc.replaceItemValue("SAPPingZheng",pzh);              //sap凭证号
                          logdoc.replaceItemValue("Memo",memo);              //备注
                      logdoc.replaceItemValue("Creater","*");
                      logdoc.getFirstItem("Creater").setAuthors(true);  
                      logdoc.save();  
                     
                }
              ///////////////在OA中记录开始写SAP的日志end
               //---------------------------------------------------------------------
    
  }catch(Exception e){
           System.out.println(e.getMessage());
       }
  }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwpwjg.html