Skip to Content
1
Former Member
Dec 17, 2013 at 12:15 PM

Error while adding a User Defined Field

383 Views

Hi Experts,

I am trying to add a UDF to the OCPR table with some valid values.

If the field already exists, we are getting a message 'ODBC -2035' Field already exists.

After upgrading to SAP 90 version, if the UDF is already there, I am getting an error with Code (-5002) with description ('No Records').

This is the code i am running

SAPbobsCOM.UserFieldsMD oUsrField = null;

int lErrCode; string sErrCode = "";

try

{

oUsrField = (SAPbobsCOM.UserFieldsMD)pSAPCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields);

oUsrField.TableName = "OCPR";

oUsrField.Name = "CntType";

oUsrField.Type = SAPbobsCOM.BoFieldTypes.db_Alpha;

oUsrField.Description = "Contact Type";

oUsrField.Size = 253;

oUsrField.EditSize = 253;

oUsrField.ValidValues.Value = "None";

oUsrField.ValidValues.Description = "None";

oUsrField.ValidValues.Add();

oUsrField.ValidValues.Value = "B1";

oUsrField.ValidValues.Description = "Bill To 1";

oUsrField.ValidValues.Add();

oUsrField.ValidValues.Value = "S1";

oUsrField.ValidValues.Description = "Ship To 1";

oUsrField.ValidValues.Add();

oUsrField.ValidValues.Value = "B2";

oUsrField.ValidValues.Description = "Bill To 2";

oUsrField.ValidValues.Add();

oUsrField.ValidValues.Value = "S2";

oUsrField.ValidValues.Description = "Ship To 2";

oUsrField.ValidValues.Add();

lErrCode = oUsrField.Add();

if (lErrCode == 0)

return 0;

else

{

pSAPCompany.GetLastError(out lErrCode, out sErrCode);

throw new Exception("Error creating APP Contact Types field : " + sErrCode);

}

}

catch (Exception ex)

{

throw ex;

}

finally

{

System.Runtime.InteropServices.Marshal.ReleaseComObject(oUsrField);

oUsrField = null;

GC.Collect();

}

Please help me to find out the reason of this error.

Thanks in advance.

Jisha