İnsert records from a table to another table different company (WİTH CODE)

Hi.İ want to ask a question.Sorry for english i dont know well.İ want to take records (ETGItemGroupTable) İN “YE01” company then i want to insert records (ETGItemGroupTable) in “AL01” company.i find another way to use buf2buf function or dicttable … but i must use like this code

(where itemGroupTable2.ItemGroupId != itemGroupTable.ItemGroupId).Because İn “AL01” company there will be records.

ETGItemGroupTable.ItemGroupId is primary key.So this i got error.İ want “AL01” company have records then this code must be updated.if “AL01” company havent racords this code must be insert.Please Help me this problem.Please write this code correctly.

ETGItemGroupTable itemGroupTable;

ETGItemGroupTable itemGroupTable2;

;

ttsbegin;

changecompany(“YE01”)

{

select itemGroupTable;

}

changecompany(“AL01”)

{

while select itemGroupTable2

where itemGroupTable2.ItemGroupId != itemGroupTable.ItemGroupId

{

itemGroupTable2.ItemGroupId = itemGroupTable3.ItemGroupId;

itemGroupTable2.ItemGroupName = itemGroupTable3.ItemGroupName;

itemGroupTable2.ItemGroupDesc = itemGroupTable3.ItemGroupDesc;

itemGroupTable2.ItemGroupLevel = itemGroupTable3.ItemGroupLevel;

itemGroupTable2.insert();

}

while select forupdate itemGroupTable2

where itemGroupTable2.ItemGroupId == itemGroupTable.ItemGroupId

{

itemGroupTable2.ItemGroupId = itemGroupTable3.ItemGroupId;

itemGroupTable2.ItemGroupName = itemGroupTable3.ItemGroupName;

itemGroupTable2.ItemGroupDesc = itemGroupTable3.ItemGroupDesc;

itemGroupTable2.ItemGroupLevel = itemGroupTable3.ItemGroupLevel;

itemGroupTable2.update();

}

}

ttscommit;

İsnt any soluiton? :frowning:

You said you got an error, but I don’t see any details. It’s difficult to give any advice if we don’t know your problem.

You just explained again what you want to achieve but not what problem you have.

Please explain what you want to ask members of this forum.

I think i explained so clearly.İ dont how to do this situation.İ dont know how to write this job.Members understand my problem.if you want error screen look at this.This says You cant transfer record.Because The primary key.İf members dont know primary key read this article from w3schools:i try this job and i got error becasue the primary key.İ think i explained so clearly in above picture.Thanks for helping.

static void kadirETGItemGroupTable1(Args _args)

{

ETGItemGroupTable itemGroupTable;

ETGItemGroupTable itemGroupTable2;

;

ttsbegin;

changecompany(“YE01”)

{

while select itemGroupTable

{

changecompany(“AL01”)

{

itemGroupTable2 = null;

buf2buf(itemGroupTable,itemGroupTable2);

itemGroupTable2.insert();

}

}

}

ttscommit;

}

The PRIMARY KEY constraint uniquely identifies each record in a database table.

Primary keys must contain unique values.

A primary key column cannot contain NULL values.

Most tables should have a primary key, and each table can have only ONE primary key.

2018.3.png

Thank you for providing the error message in the end. Could you also translate it to English or or at least put it here as text so it can be copied to a translator?

i translated into english.

in ETGItemGroupTable records can not be created.Because record already exists.

A friend help me solve my problem.This is code;

static void Job189(Args _args)

{

ETGItemGroupTable CSTable, MSTable;

DTItemGroupId idBuffer;

;

//CSTable.clear();

while select CSTable

{

idBuffer = CSTable.ItemGroupId;

changecompany(“AL01”)

{

MSTable = ETGItemGroupTable::find(idBuffer);

ttsbegin;

if(MSTable)

{

MSTable.selectforupdate(true);

MSTable.ItemGroupId = CSTable.ItemGroupId;

MSTable.ItemGroupName = CSTable.ItemGroupName;

MSTable.ItemGroupIdParent = CSTable.ItemGroupIdParent;

MSTable.ItemGroupLevel = CSTable.ItemGroupLevel;

MSTable.ItemGroupDesc = CSTable.ItemGroupDesc;

MSTable.doUpdate();

}

else

{

if(idBuffer != “”)

{

MSTable = null;

buf2buf(CSTable, MSTable);

MSTable.insert();

}

}

ttscommit;

}

idBuffer = “”;

}

}

The record you’re inserting would violate uniqueness of a unique index (not necessarily the primary index, if the table contains more unique indexes). Please look at data you’re inserting to find out which contains values already existing at time of inserting. Don’t forget to look at DataAreaId field too.

When you find wrong data, you’ll likely see what you did wrong. If not, please return here and tell us what you have found.

By the way, you should call find() in transaction as select the record for update.