OmeLuuk
23rd July 2015, 18:17
I want to share a solution with you for a situation mentioned several times on this board:
I want to use AFS in a session where I could not manage to select the right record to update although the syntax in AFS is correct. ret = stpapi.sort.by("tdisa0601m000", "1", o.err.msg)
stpapi.put.field("tdisa0601m000", "tdisa001.item.segment2",
trim$(tdisa001.item))
ret = stpapi.find("tdisa0601m000", o.err.msg)
if ret = 1 then| But once here it appears that something is DEAD WRONG
Note: I thought that the session had to be started (and finding the default record selection would be done after the index selection) before I do a put on the session, but that does not help. stpapi.get.field("tdisa0601m000", "tdisa001.item", item)| item is not the same as tdisa001.item but *another*
So I figured out the solution offered on the board, using browse.set (or browse.view, depending on the session type) but it takes an awful lot of time to get things done since we have loads of items to sell: if not ( trim$(item) = trim$(tdisa001.item) ) then
repeat
if item < tdisa001.item then
ret = stpapi.browse.set("tdisa0601m000", "next.set",
o.err.msg)
else
ret = stpapi.browse.set("tdisa0601m000", "prev.set",
o.err.msg)
endif
stpapi.get.field("tdisa0601m000", "tdisa001.item", item)
until ( trim$(item) = trim$(tdisa001.item) or ret = 0 )
endifThis works for sure, but it has to browse through all items before it may continue with the correct one. And this has to be done many times for all items on my to-do list.
When running a DBS log I noticed that the record marked as *another* item was the *saved default* item (or after I removed my defaults it appeared to be the *first* item).
Now I added a trick :D
Before the first AFS call on the session where I need the record, I trick the 4GL session by setting the defaults in the stored session defaults to my current record -> update.current.tools("tdisa0601m000", "tdisa001.item:=" &
quoted.string(tdisa001.item), ttyeno.yes)
Where the function is defined like:functions:
function update.current.tools( domain ttst13 i.sess,
domain ttst200 i.rcrd,
domain ttyeno i.socc)
{ | Note: i.socc = yes means single occ (no = multi occ)
table tttadv990
long companion
companion = get.compnr()
if compnr.check(000) then
db.retry.point()
select ttadv990.*
from ttadv990 for update
where ttadv990._compnr = 000
and ttadv990._index1 = {:logname$, :companion, :i.sess}
selectdo
db.delete(tttadv990, db.retry)
endselect
commit.transaction()
db.retry.point()
select ttadv990.*
from ttadv990 for update
where ttadv990._compnr = 000
and ttadv990._index1 = {:logname$, :companion, :i.sess}
selectdo
selectempty
ttadv990.user = logname$
ttadv990.comp = companion
ttadv990.sess = i.sess
ttadv990.sequ = 1
ttadv990.socc = i.socc
ttadv990.rcrd = i.rcrd
db.insert(tttadv990, db.retry)
endselect
commit.transaction()
endif
if compnr.check(companion) then
endif
}It seems to work fine for me ;) Please tell me if it works for you too :cool:
I want to use AFS in a session where I could not manage to select the right record to update although the syntax in AFS is correct. ret = stpapi.sort.by("tdisa0601m000", "1", o.err.msg)
stpapi.put.field("tdisa0601m000", "tdisa001.item.segment2",
trim$(tdisa001.item))
ret = stpapi.find("tdisa0601m000", o.err.msg)
if ret = 1 then| But once here it appears that something is DEAD WRONG
Note: I thought that the session had to be started (and finding the default record selection would be done after the index selection) before I do a put on the session, but that does not help. stpapi.get.field("tdisa0601m000", "tdisa001.item", item)| item is not the same as tdisa001.item but *another*
So I figured out the solution offered on the board, using browse.set (or browse.view, depending on the session type) but it takes an awful lot of time to get things done since we have loads of items to sell: if not ( trim$(item) = trim$(tdisa001.item) ) then
repeat
if item < tdisa001.item then
ret = stpapi.browse.set("tdisa0601m000", "next.set",
o.err.msg)
else
ret = stpapi.browse.set("tdisa0601m000", "prev.set",
o.err.msg)
endif
stpapi.get.field("tdisa0601m000", "tdisa001.item", item)
until ( trim$(item) = trim$(tdisa001.item) or ret = 0 )
endifThis works for sure, but it has to browse through all items before it may continue with the correct one. And this has to be done many times for all items on my to-do list.
When running a DBS log I noticed that the record marked as *another* item was the *saved default* item (or after I removed my defaults it appeared to be the *first* item).
Now I added a trick :D
Before the first AFS call on the session where I need the record, I trick the 4GL session by setting the defaults in the stored session defaults to my current record -> update.current.tools("tdisa0601m000", "tdisa001.item:=" &
quoted.string(tdisa001.item), ttyeno.yes)
Where the function is defined like:functions:
function update.current.tools( domain ttst13 i.sess,
domain ttst200 i.rcrd,
domain ttyeno i.socc)
{ | Note: i.socc = yes means single occ (no = multi occ)
table tttadv990
long companion
companion = get.compnr()
if compnr.check(000) then
db.retry.point()
select ttadv990.*
from ttadv990 for update
where ttadv990._compnr = 000
and ttadv990._index1 = {:logname$, :companion, :i.sess}
selectdo
db.delete(tttadv990, db.retry)
endselect
commit.transaction()
db.retry.point()
select ttadv990.*
from ttadv990 for update
where ttadv990._compnr = 000
and ttadv990._index1 = {:logname$, :companion, :i.sess}
selectdo
selectempty
ttadv990.user = logname$
ttadv990.comp = companion
ttadv990.sess = i.sess
ttadv990.sequ = 1
ttadv990.socc = i.socc
ttadv990.rcrd = i.rcrd
db.insert(tttadv990, db.retry)
endselect
commit.transaction()
endif
if compnr.check(companion) then
endif
}It seems to work fine for me ;) Please tell me if it works for you too :cool: