Proper ways of using TTSBEGIN and TTSCOMMIT

I need to write a code on the insert/update method of custtrans table. This code will be helpful me to insert the current recid (this.recId) of custtrans table to another table (AIFCusttrans - this table is created by me).

Such as:

public void insert()
{

;

AIFCusttrans aifCusttrans_;

select forupdate aifCusttrans_
where aifCusttrans_.RecRecId == this.RecId;

if(aifCusttrans_)
{
aifCusttrans_.RecRecId = this.RecId;
aifCusttrans_.LastUpdatedDatetime = DateTimeUtil::utcNow();
aifCusttrans_.update();

}
else
{

aifCusttrans_.RecRecId = this.RecId;
aifCusttrans_.LastUpdatedDatetime = DateTimeUtil::utcNow();
aifCusttrans_.insert();
}

}

Do i need to put the ttsbegin and ttscommit into this code? please help me.

If you are updating values and you need to do all process or nothing , you need to set it.

Thanks XBB.
Anyway. could you please tell me the purpose of adding ttsbeging and ttscommit.?

ttsbegin shows that a transactional process is starting and ttscommit is the end of the process if while process is executing an error happends all code inside of ttsbegin/ttscommit will be rollback.

It is to have a consistent data, which can not be is that part of the code is made and another not.

do we need to add ttsbegin and ttscommit all the time whenever we write an update/insert query?
is it a compulsory one?

If you do an update you need to set because is mandatory but if you are doing an insert it depends of your needs.

Thanks XBB