smusba
15th December 2014, 08:25
There are many wrong entries in the price books based on expiry date and effective date.
The case is if :for any price entry the one previous Expiry Date is greater than the next Effective Date then the previous Expiry Date should be update by the next (Effective Date -1).
I have written a logic which only works for one record. I want this logic to run for more than one record.

functions:
function read.main.table()
{ | count = 0
select a.pbor:pbor,a.prbk:prbk,a.item:item, count(a.efdt):count
from tdpcg031 a
group by a.pbor,a.prbk, a.item
selectdo

|****************************** SELECT THE LAST ROW**********************************************
select b.exdt:expdate, b.efdt:effdate
from tdpcg031 b
where b._index1 = {1,"100000006",:item.f}
order by b.exdt desc
as set with 1 rows
selectdo
endselect

|********************************SELECT THE (LAST-1)TH ROW*******************************

select c.exdt:expdate2,c.efdt:effdate2
from tdpcg031 c
where c._index1 = {1,"100000006",:item.f}
order by c.exdt desc
as set with 2 rows
selectdo
endselect
|****************************************COMPARE THE LAST TWO ROWS ****************************************
|***************************************** UPDATE (LAST-1)TH ROW IF BOTH EXPIRY DATES ARE EQUAL*************
if effdate > expdate2 and count > 1 then

db.retry.point()
select tdpcg031.*
from tdpcg031 for update
where tdpcg031._index1 = {1,"100000006",:item.f}
order by tdpcg031.efdt desc
as set with 2 rows
selectdo
selecteos

tdpcg031.exdt = expdate2 - 2
db.update(ttdpcg031,db.retry)
commit.transaction()
selectempty
endselect
else
endif
endselect
}

mark_h
15th December 2014, 17:59
I am not sure I total understand looking at the code. Why doesn't the out select with the group by have an item range like a.item inrange {:item.f} and {:item.t}. Then why don't the inner selects have :item instead of item.f.

The simplest advice I can give if the routine works for 1 record and I assume it is item - then just make it a function and pass each item you want it to work on.

Not sure I get the request - I must be missing something.