cancel
Showing results for 
Search instead for 
Did you mean: 

UDT keeps old values in user fields when adding new records

Former Member
0 Kudos

Hi all,

I am adding new records to UDT using userTable.UserFields

After I add the first record to a table, I add another one, but for the second one, I do not supply values for some of the fields.

For some reason, the userTable object "remembers" the values I used for the previoues record and inserts them to the fields of the new record.

Anyone has any idea? Workaround?

Asher

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi

If i'm not wrong then the problem can be that memory may not be released.....

try to release the memory after addition...

System.Runtime.InteropServices.Marshal.ReleaseComObject(your variable used for adding the values)

Hope it solves your problem

Thanks

Former Member
0 Kudos

Hi there,

Thanks for the reply.

I have released the table and tables com objects and got them again from the company object.

Did not solve the problem. I also tried changing the .net variable.

Did not work.

Asher

Former Member
0 Kudos

Hi,

Please post ur code here.. so that we can take at look at it.

Vasu Natari.

Former Member
0 Kudos

Hi,

Here is the code recreating the problem:

  • Table AAA has fields U_A and U_I - string and int

  • firstRun is a class variable:

  • the function is called twice and creates two records.

  • the value of U_A is 'A' in both records and the value of U_I is 3 in both records

=================================================================

Company company = Utilities.SAPApplication.GetRunningCompany();

UserTables tables = company.UserTables;

UserTable tableObjcet = tables.Item("AAA");

if (firstRun)

{

tableObjcet.Code = "00000024";

tableObjcet.Name = tableObjcet.Code;

tableObjcet.UserFields.Fields.Item("U_A").Value = "A";

tableObjcet.UserFields.Fields.Item("U_I").Value = 3;

firstRun = false;

}

else

{

tables = company.UserTables;

tableObjcet = tables.Item("AAA");

tableObjcet.Code = "00000025";

tableObjcet.Name = tableObjcet.Code;

}

int i = tableObjcet.Add();

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

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

==============================================================

Asher

former_member221340
Participant
0 Kudos

I am experiencing the same issue and do not know how to resolve it.

I am using SAP 2007A SP01 PL05.

Thank you,

Mike

Former Member
0 Kudos

After TableObjcet.Add() do TableObjcet.GetByKey("")