shellybabber
3rd March 2011, 08:08
Hi,

I am not able to write code for calculating no of days.I need to print difference(days) between tdsls401.dldt and tdsls401.ddta excluding non working days.
I am consdering Display Actual Calendar session(tcccp0530m000) based on calendar code & availability type.
I know how loop will work but not able to write the code.To my undersatnding,loop will continue until Delivery date(tdsls401.dldt) becomes equal to Planned deliver date(tdsls401.ddta) and on every cycle delivery date will be reduced by one and if new date lies between the start date(tcccp030.stdt) & end date(tcccp030.endt) according to the availability type of calendar,counter for counting no of days will be increased by one.

Can anyone help me to generate correct code for this?

My Code:-

function cal_days()
{
for tdsls401.dldt=tdsls401.ddat
select tcccp030.* from tcccp030
where tcccp030.ccal=100 |Calender Code
and tcccp030.ract=001 | Availability type as normal working days excluding Sat & sun
and tcccp030.stdt>=:dt between tcccp030.endt<=:dt
selectdo
no_of_days=no_of_days+1
selectempty

endselect
dt=tdsls401.dldt-1
end for
}

Thanks
Shelly

sameer.don
3rd March 2011, 10:17
did u try to compile this code? did it get compiled without errors?

at first, there is a syntax error in this code. And there is wrong use of operator between

The way you have used for loop is in correct, instead you should use, either REPEAT...UNTIL for WHILE..ENDWHILE loops.
eg.:

REPEAT
<your code>
UNTILL tdsls401.dldt=tdsls401.ddat


OR


WHILE tdsls401.dldt > tdsls401.ddat
<your code>
ENDWHILE



Your code can be modified as :

function cal_days()
{
dt=tdsls401.dldt
repeat
select tcccp030.*
from tcccp030
where tcccp030.ccal=100 |Calender Code
and tcccp030.ract=001 | Availability type as normal working days excluding Sat & sun
and tcccp030.stdt<=:dt
and tcccp030.endt>=:dt
selectdo
no_of_days=no_of_days+1
selectempty
endselect
dt=dt-1
until dt = tdsls401.ddat

}

mark_h
3rd March 2011, 15:40
I don't know baan 5, but that looks like an awful lot of coding for calculating the working days between two dates. My code below was what I used in 4c4: The days are coded as like HOL(Holiday), WDA (weekday), etc. Then in tirou420 it has a working time field called tirou420.pcwt. If it is greater than 0 then it is considered a working day. We typically do not use work center calendars so that is why ZZZ is included, but even if we did we can use the global calendar to get the working days between two dates. Just a thought.


select count(tirou420.pcwt):cnt.days
from tirou400,tirou420
where tirou400.cwoc ="ZZZ"
and (tirou400.date >= :start.date and tirou400.date<:stop.date)
and tirou400.ctod refers to tirou420
and tirou420.pcwt > 0
selectdo
endselect

shellybabber
10th March 2011, 08:13
thanks guys..........it works perfectly :-)