Showing posts with label Date related calucations using rowsets and without rowset. Show all posts
Showing posts with label Date related calucations using rowsets and without rowset. Show all posts

Wednesday, May 5, 2010

Date related calucations using rowsets and without rowset

Date related calucations using rowsets

Local Rowset &RS0, &RS1;
Local date &From_Date, &To_Dt;
&Duration = 0;
&Tot_Holi = 0;
&Sat = 0;
&Sun = 0;
&RS0 = GetLevel0();
&RS1 = &RS0(1).GetRowset(Scroll.SRI_STUMOD_TBL);
For &I = 1 To &RS1.ActiveRowCount
&From_Date=&RS1(I).GetRecord(Record.SRI_STUMOD_TBL).GetField(Field.SRI_STUAB_STD).Value;
&To_Dt =&RS1(&I).GetRecord(Record.SRI_STUMOD_TBL).GetField(Field.SRI_STUAB_END).Value;
While (&From_Date <= &To_Dt);

If (Weekday(&From_Date) = 7) Then
&Sat = &Sat + 1;
End-If;

If (Weekday(&From_Date) = 1) Then
&Sun = &Sun + 1;
End-If;

If Weekday(&From_Date) <> 7 And
Weekday(&From_Date) <> 1 And
&flag <> "x" Then
&Duration = &Duration + 1;

End-If;
&From_Date = AddToDate(&From_Date, 0, 0, 1);

End-While;

&RS1(&I).GetRecord(Record.SRI_STUMOD_TBL).GetField(Field.SRI_STUAB_DURATION).Value = &Duration;
If &Duration > 20 Then
Error MsgGet(11100, 180, "Only 20 leaves per annum please select the correct dates");
End-If;

&RS1(&I).GetRecord(Record.SRI_STUMOD_TBL).GetField(Field.SRI_STUAB_SAT).Value = &Sat;
WinMessage(&Sat, 0);
&Sat = 0;

&RS1(&I).GetRecord(Record.SRI_STUMOD_TBL).GetField(Field.SRI_STUAB_SUN).Value = &Sun;
&Sun = 0;

End-For;



Date related calucations without RowSet

Local date &From_Date, &To_Dt;

&Duration = 0;
&Tot_Holi = 0;
&Sat = 0;
&Sun = 0;

&From_Dt = SRI_STUMOD_TBL.SRI_STUAB_STD.Value;
&To_Dt = SRI_STUMOD_TBL.SRI_STUAB_END.Value;

While (&From_Dt <= &To_Dt);
&From_Dt = AddToDate(&From_Dt, 0, 0, 1);
If (Weekday(&From_Dt) = 7) Then
&Sat = &Sat + 1;
End-If;
If (Weekday(&From_Dt) = 1) Then
&Sun = &Sun + 1;
End-If;
If Weekday(&From_Dt) <> 7 And
Weekday(&From_Dt) <> 1 And
&flag <> "x" Then
&Duration = &Duration + 1;
End-If;

SQLExec("select 'x' from PS_HOLIDAY_DATE WHERE HOLIDAY=:1", &From_Dt, &flag);
If &flag = "x" Then
&Tot_Holi = &Tot_Holi + 1;
End-If;


End-While;
SRI_STUMOD_TBL.SRI_STUAB_SAT.Value = &Sat;
&Sat = 0;
SRI_STUMOD_TBL.SRI_STUAB_SUN.Value = &Sun;
&Sun =0;
SRI_STUMOD_TBL.SRI_STUAB_DURATION.Value = &Duration;