cancel
Showing results for 
Search instead for 
Did you mean: 

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

Former Member
0 Kudos

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(),"");

}

}

}

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Jan,

How about to SAP Business One.

At Invoke of: Update,A COM exception has been encountered

Many thanks,

MZ

Former Member
0 Kudos

After a long search I have found the answer to this proproblem myself on service.sap.com/smb note-no 706379. I have tryed it out and it WORKS. Please read the following text that explains the problem and the solution :

Symptom

Following exception or similar text found in the failed response message

COM exception has been encountered: At Invoke of: Add

Description: The server threw an exception.

Other terms

SBO ITK, Java Connector, SBO SDK, DI-API, SAP J2EE 6.20

Reason and Prerequisites

Note 642676 explains this problem in a detail.

In a brief, the main stack size is not large enough causes this

exception.

Solution

First of all, please find from which exe file the J2EE server started. For starting in the console with go.bat, the exe may be java.exe under %JAVA_HOME%\bin (Please check the path setting for which java.exe

to be used. Normally, it may be C:\WINDOWS\SYSTEM32\java.exe,

%JAVA_HOME%\bin\java.exe, %JAVA_HOME%\jre\bin\java.exe,

or C:\Program Files\JavaSoft\JRE\1.3.1_08\bin\java.exe)

For starting as the windows service, you can find the exe as following:

1. Open the service from Start -> Setting -> Control Panel ->

Adiministrative Tools -> Services

2. Find the service to start SAP J2EE 6.20 of ITK, for example,

"SAP J2EE Engine Alone"

3. Open the properites window of this service, you can find the exe in "Path to excutable", for example, d:\SAP_J2EEngine6.20\configtool\alone.exe

Second, prepare the tools to do the patch. If you have installed

Microsoft Visual Studio 6.0, you have the right tools. We need

a. editbin.exe, to patch the exe.

b. dumpbin.exe, to check the stacksize.

c. link.exe and MSPDB60.DLL to run above two tools.

Third, patch the exe:

1. BACKUP THE ORIGINAL EXE, JAVA.EXE OR ALONE.EXE

2. Use dumpbin.exe to check the original stack size

dumpbin.exe /headers alone.exe

find line: 40000 size of stack reserve

It means the current stack size is 256k

3. Use editbin.exe to patch the exe, for example with 2m stack size

2m = 2 * 1024 *1024 bytes = 2097152 bytes

editbin.exe /stack:2097152 alone.exe

4. Use dumpbin.exe to verify the patch.

dumpbin.exe /headers alone.exe

find line: 200000 size of stack reserve

It means the current stack size is 2m

Last step, start the J2EE server again and see whether everything

is OK.

For service, we also recommend you patch d:\SAP_J2EEngine6.20\configtool\service.exe All installed service exe file, for example alone.exe will be copied from this file. Patch this file will avoid patch each duplicated exe file then.

Regards

Jan Nielsen

AMC-CONSULT A/S