Please do post your comments and suggestions for me to improve on chowdary1105@gmail.com

Sunday, August 30, 2009

How to read the runcontrol parameters in AE

We can read the Runcontrol Parameters in Application Engine by the following below 2 ways:

SQL
%select(EMPLID)selct EMPLID from PS_AERUNCONTROL where PROCESS_INSTANCE=%PROCESS_INSTANCE AND OPRID=%oprid

PeopleCode
&SQL="Select EMPLID from PS_AERUNCONTROL where PROCESS_INSTANCE="|PS_TEST_AET.PROCESS_INSTANCE|"and OPRID="|%oprid


%PROCESS_INSTANCE or %Bind(PROCESS_INSTANCE) can be used.
%PROCESS_INSTANCE is more efficent and faster

Wednesday, August 19, 2009

Sample People Code for getting the DEPT ID based on the ORG ID

Below is the 3 level rowset peoplecode for getting the Department ID prompt values when we select the Organization ID from prompt table.(i'e when we select the Organization ID from the prompt table then the departments under the particular Organization should only display)
Local Rowset &RS0, &RS1, &RS2;
&RS0 = GetLevel0();
&RS1 = &RS0(1).GetRowset(Scroll.SRI_ORG1_TBL);
For &I = 1 To &RS1.ActiveRowCount
&ID = &RS1(&I).GetRecord(Record.SRI_ORG1_TBL).GetField(Field.SRI_ORG_ID).Value;
&SQL = CreateSQL("SELECT DESCR FROM PS_EXT_ORG_TBL WHERE EXT_ORG_ID=:1", &ID);
While &SQL.FETCH(&DESCR)
&RS1(&I).GetRecord(Record.SRI_ORG1_TBL).GetField(Field.SRI_ORG1_NAME).Value = &DESCR;
REM WinMessage(&DESCR, 0);


&RS2 = &RS1(&I).GetRowset(Scroll.SRI_DEPT1_TBL);


For &J = 1 To &RS2.ActiveRowCount;
&DI = &RS2(&J).GetRecord(Record.SRI_DEPT1_TBL).GetField(Field.SRI_ORG_ID).Value;
&SQL1 = CreateSQL("SELECT ORG_DEPARTMENT FROM PS_ORG_DEPT WHERE EXT_ORG_ID=:1", &DI);
While &SQL1.FETCH(&ORG_DEPARTMENT)
REM SQLEXEC("SELECT COUNT(EMPLID) FROM ");
If &ORG_DEPARTMENT = "" Then
&RS2(&J).GetRecord(Record.SRI_DEPT1_TBL).GetField(Field.SRI_DEPT_ID).Value = "";
WinMessage("There are no Departments under this Organisation ID", 0);
Else
&RS2(&J).GetRecord(Record.SRI_DEPT1_TBL).GetField(Field.SRI_DEPT_ID).Value = "";

rem WinMessage(&ORG_DEPARTMENT, 0);

End-If;
End-While;
End-For;
End-While;
End-For;

People Code for calucating the student marks,average and grade

&A = STUD_TBL.STUD_MI.Value;
&B = STUD_TBL.STUD_M2.Value;
&C = STUD_TBL.STUD_M3.Value;
STUD_TBL.STUD_TOT = &A + &B + &C;
STUD_TBL.STUD_AVG = (&A + &B + &C) / 3;
If (&A = "") Or
(&B = "") Or
(&C = "") Then
STUD_TBL.STUD_GRADE = "";
Else
If (&A < 35) Or
(&B < 35) Or
(&C < 35) Then
STUD_TBL.STUD_GRADE = "FAIL";
Else
If (STUD_TBL.STUD_AVG > 35) And
(STUD_TBL.STUD_AVG < 50) Or
(STUD_TBL.STUD_AVG > 35) And
(STUD_TBL.STUD_AVG < 50) Or
(STUD_TBL.STUD_AVG > 35) And
(STUD_TBL.STUD_AVG < 50) Then
STUD_TBL.STUD_GRADE = "C";
Else
If (STUD_TBL.STUD_AVG > 50) And
(STUD_TBL.STUD_AVG < 70) Or
(STUD_TBL.STUD_AVG > 50) And
(STUD_TBL.STUD_AVG < 70) Or
(STUD_TBL.STUD_AVG > 50) And
(STUD_TBL.STUD_AVG < 70) Then
STUD_TBL.STUD_GRADE = "B";
Else
If (STUD_TBL.STUD_AVG > 70) And
(STUD_TBL.STUD_AVG <= 100) Or
(STUD_TBL.STUD_AVG > 70) And
(STUD_TBL.STUD_AVG <= 100) Or
(STUD_TBL.STUD_AVG > 70) And
(STUD_TBL.STUD_AVG <= 100) Then
STUD_TBL.STUD_GRADE = "A"
End-If
End-If
End-If
End-If
End-If

Sample 2 level rowset code for Language selection

When we select the the language from the drop down list then the field names in two level's should change automatically.Below is the sample rowset (RS0,RS1) code for 2 levels.

Local Rowset &rs0, &rs1;
&field = GetField(SRI_ORGSAMP_TBL.SRI_ORGSAMP_ID);
&field1 = GetField(SRI_ORGSAMP_TBL.SRI_ORGSAMP_NAME);
&LABELID = &field.Name;
&LABELID1 = &field1.Name;

/*CHINEESE LANGUAGE*/
If SRI_ORGSAMP_TBL.SRI_LANGUAGE.Value = "CHIN" Or
SRI_ORGSAMP_TBL.SRI_LANGUAGE.Value = "" Then
&field.Label = "GRO DI";
&field1.Label = "GRO EMAN";
&rs0 = GetLevel0();
&rs1 = &rs0(1).GetRowset(Scroll.SRI_EMPSAMP_TBL);
For &i = 1 To &rs1.ActiveRowCount
/*Variable*/
&empid = &rs1(&i).GetRecord(Record.SRI_EMPSAMP_TBL).GetField(Field.SRI_EMPSAMP_ID);
&empid.Label = "EEOLPME DI";
&NAME = &rs1(&i).GetRecord(Record.SRI_EMPSAMP_TBL).GetField(Field.SRI_EMPSAMP_NAME);
&NAME.Label = "EMAN";
&GENDER = &rs1(&i).GetRecord(Record.SRI_EMPSAMP_TBL).GetField(Field.SRI_EMPSAMP_GENDER);
&GENDER.Label = "REDNEG";
&COUN = &rs1(&i).GetRecord(Record.SRI_EMPSAMP_TBL).GetField(Field.SRI_EMPSAMP_COUN);
&COUN.Label = "GNIKROW NOITACOL";
&DOB = &rs1(&i).GetRecord(Record.SRI_EMPSAMP_TBL).GetField(Field.SRI_EMPSAMP_DOB);
&DOB.Label = "BOD";
&DOJ = &rs1(&i).GetRecord(Record.SRI_EMPSAMP_TBL).GetField(Field.SRI_EMPSAMP_DOJ);
&DOJ.Label = "JOD";
End-For;

End-If;
/*END OFCHINEESE LANGUAGE*/
/*FRANCE LANGUAGE*/
If SRI_ORGSAMP_TBL.SRI_LANGUAGE.Value = "FRAN" Or
SRI_ORGSAMP_TBL.SRI_LANGUAGE.Value = "" Then
&field.Label = "ORGANI ID";
&field1.Label = "NAMEE";
&rs0 = GetLevel0();
&rs1 = &rs0(1).GetRowset(Scroll.SRI_EMPSAMP_TBL);
For &i = 1 To &rs1.ActiveRowCount
/*Variable*/
&empid = &rs1(&i).GetRecord(Record.SRI_EMPSAMP_TBL).GetField(Field.SRI_EMPSAMP_ID);
&empid.Label = "EMPOLOD ID";
&NAME = &rs1(&i).GetRecord(Record.SRI_EMPSAMP_TBL).GetField(Field.SRI_EMPSAMP_NAME);
&NAME.Label = "NAMEE";
&GENDER = &rs1(&i).GetRecord(Record.SRI_EMPSAMP_TBL).GetField(Field.SRI_EMPSAMP_GENDER);
&GENDER.Label = "DREE";
&COUN = &rs1(&i).GetRecord(Record.SRI_EMPSAMP_TBL).GetField(Field.SRI_EMPSAMP_COUN);
&COUN.Label = "Workingo Locationio";
&DOB = &rs1(&i).GetRecord(Record.SRI_EMPSAMP_TBL).GetField(Field.SRI_EMPSAMP_DOB);
&DOB.Label = "birtho";
&DOJ = &rs1(&i).GetRecord(Record.SRI_EMPSAMP_TBL).GetField(Field.SRI_EMPSAMP_DOJ);
&DOJ.Label = "joino";
End-For;

End-If;
/*END OF FRANCE LANGUAGE*/

/*ENGLISH LANGUAGE*/
If SRI_ORGSAMP_TBL.SRI_LANGUAGE.Value = "ENG" Or
SRI_ORGSAMP_TBL.SRI_LANGUAGE.Value = "" Then
&field.Label = "ORGANIZATION ID";
&field1.Label = "ORG NAME";
&rs0 = GetLevel0();
&rs1 = &rs0(1).GetRowset(Scroll.SRI_EMPSAMP_TBL);
For &i = 1 To &rs1.ActiveRowCount
/*Variable*/
&empid = &rs1(&i).GetRecord(Record.SRI_EMPSAMP_TBL).GetField(Field.SRI_EMPSAMP_ID);
&empid.Label = "EMPLOYEE ID";
&NAME = &rs1(&i).GetRecord(Record.SRI_EMPSAMP_TBL).GetField(Field.SRI_EMPSAMP_NAME);
&NAMELabel = "NAME";
&GENDER = &rs1(&i).GetRecord(Record.SRI_EMPSAMP_TBL).GetField(Field.SRI_EMPSAMP_GENDER);
&GENDER.Label = "GENDER";
&COUN = &rs1(&i).GetRecord(Record.SRI_EMPSAMP_TBL).GetField(Field.SRI_EMPSAMP_COUN);
&COUN.Label = "WORKING LOCATION ";
&DOB = &rs1(&i).GetRecord(Record.SRI_EMPSAMP_TBL).GetField(Field.SRI_EMPSAMP_DOB);
&DOB.Label = "DATE OF BIRTH";
&DOJ = &rs1(&i).GetRecord(Record.SRI_EMPSAMP_TBL).GetField(Field.SRI_EMPSAMP_DOJ);
&DOJ.Label = "DATE OF JOIN";
End-For;

End-If;
/*END OF ENGLISH LANGUAGE*/

Thursday, August 13, 2009

To get the OprID for the Current Session

For getting the OprID for the current session then write the following below line of code in Record Level Save PreChange Event

SRI_STUORG4_TBL.SRI_STUORG_OPRID = %UserId;

select any check box in the Grid then the remaning check boxes in the same column should hide automatically

Level 0 = Org ID,Name
Level 1 = Org details
Level 2 = 3 Grids (Active locations,Primary Contact,Active Departments)


When we select any check box then the remaning check boxes in the same column should hide automatically.And the corresponding Name (Active locations,Primary Contact,Active Departments)which is in grid should be displayed in the Corresponding fields.

Write the following below code in the Component Record Level Field change event.

Local Rowset &RS0, &RS1, &RS2, &rs4;
&RS0 = GetLevel0();
&RS1 = &RS0(1).GetRowset(Scroll.SRI_STUORG1_TBL);
&CNT = 0;
For &I = 1 To &RS1.ActiveRowCount
&RS2 = &RS1(&I).GetRowset(Scroll.SRI_STUORG3_TBL);
For &J = 1 To &RS2.ActiveRowCount
&chk = &RS2.GetRow(&J).GetRecord(Record.SRI_STUORG3_TBL).GetField(Field.SRI_ORG_PRIMARY).Value;
&cr = CurrentRowNumber(2);


If &RS2.GetRow(&J).GetRecord(Record.SRI_STUORG3_TBL).GetField(Field.SRI_ORG_PRIMARY).Value = "Y" Then

&id = &RS2.GetRow(&J).GetRecord(Record.SRI_STUORG3_TBL).GetField(Field.SRI_ORG_CONTACTNO).Value;
&RS2.GetRow(&J).GetRecord(Record.SRI_STUORG3_TBL).GetField(Field.SRI_ORG_PRIMARYCOU).Value = &id;


&CNT = &CNT + 1;

For &p = 1 To &RS2.ActiveRowCount
REM WinMessage("in for ", 0);
&RS2.GetRow(&p).GetRecord(Record.SRI_STUORG3_TBL).GetField(Field.SRI_ORG_PRIMARY).Visible = False;
End-For;
&RS2.GetRow(&cr).GetRecord(Record.SRI_STUORG3_TBL).GetField(Field.SRI_ORG_PRIMARY).Visible = True;
REM WinMessage("count " | &CNT, 0);
End-If;

If &RS2.GetRow(&J).GetRecord(Record.SRI_STUORG3_TBL).GetField(Field.SRI_ORG_PRIMARY).Value = "N" And
&CNT = 0 Then

&RS2.GetRow(&J).GetRecord(Record.SRI_STUORG3_TBL).GetField(Field.SRI_ORG_PRIMARYCOU).Value = &id;
REM WinMessage("in if1", 0);
&RS2.GetRow(&J).GetRecord(Record.SRI_STUORG3_TBL).GetField(Field.SRI_ORG_PRIMARY).Visible = True;

End-If;


If &RS2.GetRow(&J).GetRecord(Record.SRI_STUORG3_TBL).GetField(Field.SRI_ORG_PRIMARY).Value = "N" And
&CNT > 0 Then

&RS2.GetRow(&J).GetRecord(Record.SRI_STUORG3_TBL).GetField(Field.SRI_ORG_PRIMARYCOU).Value = &id;
If &J <> &cr And
&RS2.GetRow(&cr).GetRecord(Record.SRI_STUORG3_TBL).GetField(Field.SRI_ORG_PRIMARY).Value = "Y" Then
REM WinMessage("in if2", 0);
&RS2.GetRow(&J).GetRecord(Record.SRI_STUORG3_TBL).GetField(Field.SRI_ORG_PRIMARY).Visible = False;
End-If;


If &RS2.GetRow(&cr).GetRecord(Record.SRI_STUORG3_TBL).GetField(Field.SRI_ORG_PRIMARY).Value = "N" Then
&RS2.GetRow(&J).GetRecord(Record.SRI_STUORG3_TBL).GetField(Field.SRI_ORG_PRIMARYCOU).Value = &id;
For &u = 1 To &RS2.ActiveRowCount
REM WinMessage("in if2", 0);
&RS2.GetRow(&u).GetRecord(Record.SRI_STUORG3_TBL).GetField(Field.SRI_ORG_PRIMARY).Visible = True;
End-For;
End-If;
End-If;

End-For;

End-For;

Tuesday, August 11, 2009

Fill color in grid Cell

FOR &Z = 1 TO &RS.ACTIVEROWCOUNT
&RS(&Z).RSRECNAME.RECFIELDNAME.Style = "STYLEVALUE";
END-FOR

Date display format on Page

In Order to change the date format through Personalization, please follow the steps given below:

1. Navigate, Root > People Tools > Personalization > Personalization Options > Search

Here, you will get the option for the different application for which you want to change the Date Format or you can also choose PPTL (People Tools) which change the Date Format in the Tools itself. Select, PPTL.

2. Now, you can see there is a Definition---> DFRMT, for the Date Format.

3. On the Top of this page and beside the Definition Tab, you will find the Format Tab, just click on this Tab.

4. Now, click on the "Set Option Default Value".

5. Change the Option Default Value as per your requirement MMDDYY and click OK.

6. Save the changes.

========================================
========================================

If you want to change the Date Format for a Specific User on specific page then you can also do this through People Coding.

You can also play with the below code with the help of %oprid, like if %oprid then the below code or w.r.t roles through "IsUserInRole" function.

There is one built-in function "DateTimeToLocalizedString". You can use this if you want to change the date format through people code for your PIA pages.

How to use:

Example 1:
&String = DateTimeToLocalizedString(&Date, "M/d/y");
/* if you are picking the date from any record field and using &Date for that field */

Example 2:
&String = DateTimeToLocalizedString(%Date, "M/d/y");
/* if you want to pick the system date and want to use it on your page with different formats. */

-- Assign this String variable (&String) to your desired field.

Note: Here 'd' for date and 'y' for year both must be in smaller letters only. And, 'M' for months should be in Caps.

For getting the current DAteTime when ever we change or edit any field i

Write the following below code in the Record Level in Save Prechange

Local Rowset &RS0, &RS1, &RS2;

&RS0 = GetLevel0();
&RS1 = &RS0(1).GetRowset(Scroll.SRI_STUORG1_TBL);
For &I = 1 To &RS1.ActiveRowCount
&RS2 = &RS1(&I).GetRowset(Scroll.SRI_STUORG4_TBL);
For &J = 1 To &RS2.ActiveRowCount

If &RS2.GetRow(&J).IsChanged Then

&RS2.GetRow(&I).GetRecord(Record.SRI_STUORG4_TBL).GetField(Field.SRI_STUORG_DTTIME).Value = %Datetime;
End-If;

End-For;
End-For;

Sunday, August 9, 2009

Inserting a New Scroll Row from within the Same Scroll

In PeopleCode, when inserting or deleting a row on a scroll, it is required that you perform the action on a parent row of the rowset being inserted/deleted to. PeopleTools doesn’t allow PeopleCode (using the built-in functions/methods InsertRow and DeleteRow) to insert or delete a row on the same scroll within which it is currently running. If you attempt to do this, PeopleTools will give an error complaining about changing the current program context.

However, there are some cases where inserting within the same scroll might be desirable. For example, based on the data entered on a row of a scroll, a new matching row must be inserted within the same scroll.

Background

The Rowset class has a SelectNew method, which is quite similar to the Select method. The main difference is that rows populated through SelectNew are marked as new in the component buffer. Both Select and SelectNew allows the record source of the data being loaded to the rowset to be different from the primary record of the rowset. There is a requirement, however, that the source record must contain at least one of the key fields in the primary record. Though, none of the fields in the source record have to be keys as well.
The Technique

Step 1. Create a new Dynamic View record containing at least one of the keys of the primary record of the scroll. For this tutorial, assume that the name of the new record is SCROLL_INS_ROW. This is important: none of the fields in this record must be set to a key.

Step 2. Set the SQL of the view to the following:


SELECT NULL
FROM PS_INSTALLATION

Of course, if you’ve included more fields, then SELECT the appropriate number of NULL’s on the SQL.

Step 3. The PeopleCode for inserting a row within the same scroll would be the following:


Local Rowset &this_rowset = GetRowset();
&this_rowset.SelectNew(Record.SCROLL_INS_ROW);

Month difference PeopleCode

Function diff_months(&DATE1 As date, &DATE2 As date) Returns number;
Local integer &YEAR1 = Year(&DATE1);
Local integer &MONTH1 = Month(&DATE1);
Local integer &DAY1 = Day(&DATE1);
Local integer &YEAR2 = Year(&DATE2);
Local integer &MONTH2 = Month(&DATE2);
Local integer &DAY2 = Day(&DATE2);
If &DATE1 <= &DATE2 Then
If &DAY1 > &DAY2 Then
If &MONTH1 = 12 Then
&MONTH1 = 1;
&YEAR1 = &YEAR1 + 1;
Else
&MONTH1 = &MONTH1 + 1;
End-If;
End-If;
Else
If &DAY1 < &DAY2 Then
If &MONTH2 = 12 Then
&MONTH2 = 1;
&YEAR2 = &YEAR2 + 1;
Else
&MONTH2 = &MONTH2 + 1;
End-If;
End-If;
End-If;
Local integer &DIFF_MONTHS = 12 * (&YEAR2 - &YEAR1) + &MONTH2 - &MONTH1;
Return &DIFF_MONTHS;

End-Function;

File operations using DOS commands in SQR

We can use the following as an sqc, for performing file operations in SQR.

!*********************************************************************
!Program Name : FileOprs.sqc
!Description : File operations using DOS commands.
!*********************************************************************

!*********************************************************************
!Procedure Name : Make_Dir
!Description : Creates a new path based on the input. Path must be
! a complete directory tree listing.
!Usage : Do Make_Dir($Directory_NewPath)
!*********************************************************************
begin-procedure Make_Dir($NewPath)
#debugy show ‘In Procedure : Make_Dir’

Let $Commmand_line = ‘cmd /c mkdir ‘ || $NewPath
Do Exec_Cmd($Commmand_line)

end-procedure ! Make_Dir

!*********************************************************************
!Procedure Name : Exec_Cmd
!Description : Executes $Commmand_line on the system and reports
! errors for debugging.
!Usage : Do Exec_Cmd($Commmand_line)
!*********************************************************************
begin-procedure Exec_Cmd($Commmand_line)
#debugy show ‘In Procedure : Exec_Cmd’

call system using $Commmand_line #status nowait
If #status <> 0
#debugy show ‘Command ‘ $Commmand_line ‘ failed to execute.’
End-If

end-procedure ! Exec_Cmd

!*********************************************************************
!Procedure Name : Copy_Files
!Description : Copy files from old to new path. Old information should be of
! form \pathname\filename, while new information can just be a path.
!Usage : Do Copy_Files($old_file_name, $new_file_name)
!*********************************************************************
begin-procedure Copy_Files($old, $new)
#debugy show ‘In Procedure : Copy_Files’

Let $Commmand_line = ‘cmd /c copy ‘ || $old || ‘ ‘ || $new
Do Exec_Cmd($Commmand_line)

end-procedure ! Copy_Files

!*********************************************************************
!Procedure Name : Move_Files
!Description : Move files from old to new path. Old information should be of
! form \pathname\filename, while new information can just be a path.
!Usage : Do Move_Files($old_file_name, $new_file_name)
!*********************************************************************
begin-procedure Move_Files($old, $new)
#debugy show ‘In Procedure : Move_Files’

Let $Commmand_line = ‘cmd /c move ‘ || $old || ‘ ‘ || $new
Do Exec_Cmd($Commmand_line)

end-procedure ! Move_Files

!*********************************************************************
!Procedure Name : Delete_Files
!Description : Deletes the files passed in variable $files
!Usage : Do Delete_Files($files)
!*********************************************************************
begin-procedure Delete_Files($files)
#debugy show ‘In Procedure : Delete_Files’

Let $Commmand_line = ‘cmd /c del ‘ || $files
Do Exec_Cmd($Commmand_line)

end-procedure ! Delete_Files

Running an SQR from within your PeopleCode program

The best and safest way to launch an SQR program is to use the PeopleCode functions CreateProcessRequest() and Schedule().

The CreateProcessRequest function allows you to create a ProcessRequest object.
The CreateProccessRequest function takes 2 arguments. The Process Type and the Process Name.

REM Declare your Variables;
Local ProcessRequest &MYRQST;
Local String &MySQR;
&MySQR = "DDDAUDIT"
REM Create My Process Request Object;
&MYRQST = CreateProcessRequest("SQR Process", &MySQR);

REM Set Properties of My Process Request Object;
&MYRQST.RunControlID = "MYRUNCNTRL_ID"

REM Set Properties of My Process Request Object;
&MYRQST.SetOutputOption("Web", "PDF", "", &MySQR);


The above example creates a ProcessRequest object for the DDDAUDIT SQR named &MYRQST. Also specified Run Control ID and the output options. I can now take this Object and use the Schedule() method agains it to Schedule the SQR. Here is an example.

&MYRQST.Schedule();
If &MYRQST.Status = 0 then
/* Schedule succeeded. */
Else
/* Process (job) not scheduled, do error processing */
End-If;

Date related calucations

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;

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;