Skip to Content
0
Former Member
Aug 17, 2004 at 12:06 PM

A COM exception has been encountered: At invoke of: ADD The server threw an

1379 Views

Hi,

we are using the Java Connector, and I can add or update Business Partners.

But adding or updating an JournalVouchers allways throws the following COM Exception

on a SBO 6.5. Our programm-code works on a SBO 6.2, but not on a SBO 6.5 ?

What is wrong ? Can anybody tell us that ?

Regards

Jan Nielsen

AMC-CONSULT A/S

====== error mesage ======

com.sap.smb.sbo.wrapper.com.ComFailException: A COM exception has been encountered:

At Invoke of: Add

Description: The server threw an exception.

====== Programcode ==============

/*

  • Created on 25-09-2003

*

  • To change the template for this generated file go to

  • Window>Preferences>Java>Code Generation>Code and Comments

*/

package amc.sap.util;

import java.io.BufferedReader;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.FileReader;

import java.io.IOException;

import java.util.Date;

import amc.language.Language;

import amc.xkernel.exception.SetThrowException;

import amc.xkernel.global.BoxPane;

import amc.xkernel.global.Convert;

import amc.xkernel.global.DateX;

import amc.xkernel.global.SysLog;

import amc.sap.table.SalarySetupTable;

import amc.sap.table.SalarySetupTrans;

import com.sap.smb.sbo.api.IJournalEntries;

import com.sap.smb.sbo.api.IJournalEntries_Lines;

import com.sap.smb.sbo.api.IChartOfAccounts;

import com.sap.smb.sbo.api.SBOCOMUtil;

import com.sap.smb.sbo.api.SBOErrorMessage;

import com.sap.smb.sbo.util.ConvertUtil;

/**

  • @author Administrator

*

  • To change the template for this generated type comment go to

  • Window>Preferences>Java>Code Generation>Code and Comments

*/

public class MultidataImport extends SAPLogonUtil

{

private int lineNo = 0;

public static void FileCopy(String srcFileName, String destFileName)

{

try

{

File srcFile = new File(srcFileName);

if (srcFile.exists())

{

File destFile = new File(destFileName);

FileInputStream in = new FileInputStream(srcFile);

FileOutputStream out = new FileOutputStream(destFile);

int ret;

for (;(ret = in.read()) != -1;)

{

out.write(ret);

}

in.close();

out.close();

}

}

catch (Throwable e)

{

SysLog.setError(e.getMessage(),"");

}

}

private SBOErrorMessage errMsg = null;

private IJournalEntries iJournalEntries = null;

private IChartOfAccounts iChartOfAccounts = null;

private IJournalEntries_Lines iJournalEntries_Lines = null;

private boolean iJournalEntriesOK = false;

private int recCounter = 0;

private SalarySetupTable salarySetupTable = null;

private boolean errorsFound = false;

File fileName = null;

/**

*/

public MultidataImport()

{

super();

}

public void insertRecord(String record) throws Exception

{

try

{

SalarySetupTrans salarySetupTrans = new SalarySetupTrans();

String strDate = null;

Date entryDate = null;

String salaryCode = null;

String debetCredit = null;

String entryAccount = null;

String entryText = null;

String intAmount = null;

Double amount = Convert.string2Double("0.00");

Double emptyDouble = Convert.string2Double("0.00");

if (record.substring(0, 2).toString().equalsIgnoreCase("ML"))

{

/** Entrydate*/

strDate =

Convert.subString(record, 21, 4)

+ "-"

+ Convert.subString(record, 25, 2)

+ "-"

+ Convert.subString(record, 27, 2);

entryDate = ConvertUtil.DateString2Date(strDate);

/** Salarycode */

salaryCode = Convert.subString(record, 38, 4);

/** Identyfier for Debet or Credit amount */

debetCredit = Convert.subString(record, 42, 1);

/** Amount */

intAmount =

Convert.subString(record, 43, 10)

+ "."

+ Convert.subString(record, 53, 2);

amount = Convert.string2Double(intAmount);

/**

  • Fillout the IJournalEntries

*/

salarySetupTrans.setWhereFirstOnly(SalarySetupTrans.SalaryId"='"salaryCode+"'");

if (iJournalEntriesOK == false)

{

iJournalEntries.setMemo(Language.get("@ImportML"));

iJournalEntries.setReferenceDate(entryDate);

iJournalEntries.setStornoDate(entryDate);

iJournalEntries.setTaxDate(entryDate);

iJournalEntries_Lines = iJournalEntries.getLines();

iJournalEntriesOK = true;

}

if (iJournalEntriesOK == true)

{

/**

  • Fillout the IJournalEntries_Lines

*/

/** Fetch account from from DB */

entryAccount = salarySetupTrans.accountId;

/** Fetch Entrytext from DB */

entryText = salarySetupTrans.entryText;

/** Make debet Line. */

if(lineNo >= 1)

{

lineNo = lineNo + 1;

Integer integer_ = new Integer(lineNo);

iJournalEntries_Lines.setCurrentLine(integer_);

}

iJournalEntries_Lines.setAccountCode(entryAccount);

if (debetCredit.equalsIgnoreCase("+"))

{

iJournalEntries_Lines.setDebit(amount);

iJournalEntries_Lines.setCredit(emptyDouble);

}

else

{

iJournalEntries_Lines.setCredit(amount);

iJournalEntries_Lines.setDebit(emptyDouble);

}

iJournalEntries_Lines.setDueDate(entryDate);

iJournalEntries_Lines.setLineMemo(entryText);

iJournalEntries_Lines.setReferenceDate1(entryDate);

iJournalEntries_Lines.setShortName(entryAccount);

iJournalEntries_Lines.setTaxDate(entryDate);

iJournalEntries_Lines.add();

errMsg = iCompany.getLastError();

if (errMsg.getErrorCode() != 0)

{

iJournalEntriesOK = false;

throw new Exception("Could not create Journalentry "

+ "\nReason code: "

+ errMsg.getErrorCode()

+ "\nLongtext: "

+ errMsg.getErrorMessage());

}

lineNo = lineNo + 1;

Integer integer1_ = new Integer(lineNo);

iJournalEntries_Lines.setCurrentLine(integer1_);

/** Make credit Line */

/** Fetch setoffaccount from from DB */

entryAccount = salarySetupTrans.setOffAccountId;

iJournalEntries_Lines.setAccountCode(entryAccount);

if (debetCredit.equalsIgnoreCase("+"))

{

iJournalEntries_Lines.setDebit(emptyDouble);

iJournalEntries_Lines.setCredit(amount);

}

else

{

iJournalEntries_Lines.setCredit(emptyDouble);

iJournalEntries_Lines.setDebit(amount);

}

iJournalEntries_Lines.setDueDate(entryDate);

iJournalEntries_Lines.setReferenceDate1(entryDate);

iJournalEntries_Lines.setShortName(entryAccount);

iJournalEntries_Lines.setTaxDate(entryDate);

iJournalEntries_Lines.setLineMemo(entryText);

iJournalEntries_Lines.add();

recCounter = recCounter + 1;

errMsg = iCompany.getLastError();

if (errMsg.getErrorCode() != 0)

{

iJournalEntriesOK = false;

throw new Exception("Could not create Journalentry "

+ "\nReason code: "

+ errMsg.getErrorCode()

+ "\nLongtext: "

+ errMsg.getErrorMessage());

}

}

}

}

catch (SetThrowException s)

{

SysLog.setError(s.getMessage(),"");

}

catch (Exception e1)

{

SysLog.setError(Language.get("@AddFail"),e1.toString());

}

}

public void validateRecord(String record)

{

try

{

SalarySetupTrans salarySetupTrans = new SalarySetupTrans();

String salaryCode = null;

if (record.substring(0, 2).toString().equalsIgnoreCase("ML"))

{

/** Entrydate*/

//** Salarycode */

salaryCode = Convert.subString(record, 38, 4);

/** Identyfier for Debet or Credit amount */

/**

  • Check salarycodes and SAP Ledgeraccounts

*/

salarySetupTrans.setWhereFirstOnly(SalarySetupTrans.SalaryId"='"salaryCode+"'");

if(!salarySetupTrans.found())

{

SysLog.setError(Language.get("@SalarycodeNotFound",salaryCode),Language.get("@SalarycodeNotFoundHELP"));

errorsFound = true;

}

else

{

if(salarySetupTrans.accountId == "")

{

SysLog.setError(Language.get("@AccountIdNotFound",salaryCode),Language.get("@AccountIdNotFoundHELP"));

errorsFound = true;

}

else

if(!iChartOfAccounts.getByKey(salarySetupTrans.accountId))

{

SysLog.setError(Language.get("@AccountIdNotExist",salarySetupTrans.accountId),Language.get("@AccountIdNotExistHELP"));

errorsFound = true;

}

if(salarySetupTrans.setOffAccountId == "")

{

SysLog.setError(Language.get("@SetOffAccountIdNotFound",salaryCode),Language.get("@SetOffAccountIdNotFoundHELP"));

errorsFound = true;

}

else

if(!iChartOfAccounts.getByKey(salarySetupTrans.setOffAccountId))

{

SysLog.setError(Language.get("@SetOffAccountIdNotExist",salarySetupTrans.setOffAccountId),Language.get("@SetOffAccountIdNotExistHELP"));

errorsFound = true;

}

}

}

else

{

SysLog.setInfo(Language.get("@WrongFileType",fileName.getAbsolutePath()),Language.get("@WrongFileTypeHELP"));

errorsFound = true;

return;

}

}

catch (SetThrowException i)

{

SysLog.setError(i.getMessage(),"");

}

}

public void run(boolean showBoxes)

{

int je;

String fileNameStr = null;

File backupFile = null;

File backupDir = null;

FileReader fileReader = null;

BufferedReader read = null;

String readLine = null;

String content = null;

iJournalEntriesOK = false;

if (iCompany == null)

MultidataImport.tryLogon(false);

if (iCompany == null)

return;

try

{

salarySetupTable = new SalarySetupTable();

salarySetupTable.setWhereFirstOnly();

fileNameStr = salarySetupTable.salaryImportFile;

if (fileNameStr == null || fileNameStr.equalsIgnoreCase(""))

{

SysLog.setError(Language.get("@NoImportfile"),Language.get("@NoImportfileHELP"));

return;

}

backupFile = new File(salarySetupTable.salaryMoveTo"
"
DateX.getSystemDateString()Convert.stringRemove( DateX.getSystemTime(),":")".bak");

backupDir = new File(salarySetupTable.salaryMoveTo);

fileName = new File(fileNameStr);

if (!fileName.exists())

{

SysLog.setError(Language.get("@FileNoExist",fileName.getAbsolutePath()),Language.get("@FileNoExistHELP"));

return;

}

if ( !backupDir.exists() )

{

SysLog.setError(Language.get("@BackupDirNoExist",backupDir.getAbsolutePath()),Language.get("@BackupDirNoExistHELP"));

return;

}

if(showBoxes)

{

if (BoxPane.okCancel(Language.get("@OKtoImport")" "Language.get("@Multidata"),"Multidata-import") != 0)

return;

}

iJournalEntries = SBOCOMUtil.newJournalEntries(iCompany);

iChartOfAccounts = SBOCOMUtil.newChartOfAccounts(iCompany);

fileReader = new FileReader(fileName);

read = new BufferedReader(fileReader);

while (((readLine = read.readLine()) != null))

{

content = readLine;

if (!content.equalsIgnoreCase(""))

{

this.validateRecord(content);

}

}

if(errorsFound == true)

{

SysLog.setError(Language.get("@ErrorsFound"),Language.get("@ErrorsFoundHELP"));

fileReader.close();

read.close();

return;

}

fileReader.close();

read.close();

fileReader = new FileReader(fileName);

read = new BufferedReader(fileReader);

while (((readLine = read.readLine()) != null))

{

content = readLine;

if (!content.equalsIgnoreCase(""))

{

this.insertRecord(content);

}

}

if (iJournalEntriesOK == true)

{

je = iJournalEntries.add();

if (je != 0L)

{

iJournalEntriesOK = false;

errMsg = iCompany.getLastError();

SysLog.setError(Language.get("@NotCreatedJEntry")

+ "\n"+Language.get("@ReasonCode")

+ errMsg.getErrorCode()

+ "\n"+Language.get("@ErrorMessage")

+ errMsg.getErrorMessage()

,Language.get("@ConnectErrorHELP"));

}

else

{

SysLog.setInfo(Language.get("@CreatedJEntry",String.valueOf(recCounter)),"");

}

}

if(iJournalEntriesOK == true)

{

FileCopy(fileName.getAbsolutePath(),backupFile.getAbsolutePath());

}

fileReader.close();

read.close();

if (backupFile.exists())

fileName.delete();

}

catch (SetThrowException t)

{

SysLog.setError(t.getMessage(),"");

}

catch (IOException i)

{

SysLog.setError(i.getMessage(),"");

}

catch (Exception s)

{

SysLog.setError(s.getMessage(),"");

}

}

}