jaycee99
2nd July 2008, 11:27
I'm trying to do a checking on a record, if the record not exist then i want to insert a record for it. What is the proper way to do this? For example:

if tcibd003.unit = "kgs" then
(condition)
else
(insert a new record using db.insert with the value for tcibd003.unit = kgs)
endif

bdittmar
2nd July 2008, 11:53
I'm trying to do a checking on a record, if the record not exist then i want to insert a record for it. What is the proper way to do this? For example:

if tcibd003.unit = "kgs" then
(condition)
else
(insert a new record using db.insert with the value for tcibd003.unit = kgs)
endif

Hello,

db.retry.point()

select fields
from table
where <condition>
selectdo

selectempty

<assign values>
db.insert()
commit.transaction()

endselect
commit.transaction()


Regards

jaycee99
2nd July 2008, 12:17
Hi Bernd,

I tried like this, its not working.

{

select tcibd003.*
from tcibd003
where tcibd003.item = :itemtest
selectdo
if tcibd003.unit = "kgs" then
message("A")
else
message("B")

db.retry.point()
tcibd003.unit = "kgs"
db.insert(ttcibd003,db.retry)
commit.transaction()

endif
endselect
commit.transaction()

}

The session hang.

saumya
2nd July 2008, 13:47
Hi,
can u tell wht index table tcibd003 is having??

bdittmar
2nd July 2008, 15:29
Hi Bernd,

I tried like this, its not working.

Hello, this can't work !


function myfunction()
{

db.retry.point()

select tcibd003.*
from tcibd003 for update
where tcibd003.item = :itemtest
selectdo
if tcibd003.unit = "kgs" then
message("A")
else
message("B")

tcibd003.unit = "kgs"
db.update(ttcibd003,db.retry)
commit.transaction()

endif
endselect
commit.transaction()

}

The session hang.

I've modified your statement.

Regards

jaycee99
3rd July 2008, 05:40
Any idea for this? Or the proper way to solve this?

zardoz
3rd July 2008, 11:45
You are using a session type 3 - this means that the record cannot be saved until the primary key (and all other required fields) are filled... the save button is disabled because there is no record to save.
To know why the session hangs you have to post the code, without this is impossible to give you a valid answer.

jaycee99
7th July 2008, 05:39
Hi Zardoc,

From where can i change the session type? In my program script, it wrote there Type 4. The script is like i put in this forum.

jaycee99
7th July 2008, 05:42
Hi Saumya,

The index key for table tcibd003 is item, citg, basu and unit.

jaycee99
7th July 2008, 05:47
Hi Bernd,

I have tried the modified statement also cannot work. I think i have to try another way. Is there any sample script to add a new record for a table which not link to this session? For example, session A have table A, when we save, it will save to table A and table B.

kbabu1
7th July 2008, 12:15
db.retry.point()

select <table fields>
from <table> for update
where <conditions>
selectdo[/selectempty]
if <condition to isert record> then
db.set.to.default(t<table>)
<set key field values - Mandatory>
<set other fields - optional>
if db.insert(t<table>, db.retry) = 0 then
commit.transaction()
else
message("Error " & str$(e) & " occured while inserting record in table <table>"
abort.transaction()
endif
endif
endselect