Sage-ST ä Tutorial
Lesson 7





1. Overview. In this lesson you will add code to the Edit_Employee procedures to ensure that the Org number associated with the employee is valid (i.e., already exists in the data base).

2. What You'll Use. You will use your text editor and GRAPL. The following new Sage-ST calls will be used:

Sage.ReadRecordR,
Sage.FindRecordR. (not supported by GRAPL)


3. Assignment.
Currently, the user simply enters all data about each employee and that data are written to EMPLOYEE.DAT. But what if the user enters an Org number which is not valid? Now the integrity of the information in the data base has been compromised--an employee is associated with an organization which does not exist!

There are several ways to eliminate the possibility of this happening. We will check the Org number entered by the user against those actually in the Org relation just prior to doing the Write- or ReWriteRecord. If the number is not found (i.e., SageError is not 0), display a message to the user stating that the Org number is invalid. Do not add/modify the record.


4. Our Solution.



with Display;
with ModSys ;
with Sage ;
with SageLib;
with Strings;



procedure HRS is
--*
-- HRS - Sage-ST training class Prototype 8 (GRAPL)
--
-- Author - M.L. Taylor 5 Feb 1990
-- modified KABHaar 7 Nov 1990
--
-- The goal of Prototype 8 is to add code to the Edit_Employee procedure to
-- to ensure that the Org number associated with the employee is valid.
--
-- CALLING SEQUENCE -
--
-- GRAPL HRS
--
-- ENTRY -
--
-- EXIT -
--


option : string (1..1); -- not supported by GRAPL := (others => ascii.nul);


procedure Load_Employee is . . .


procedure Unload_Employee is . . .


procedure Display_Edit_Message (operation : in string) is . . .


procedure Add_Employee is
--*
-- Add_Employee
--
-- Author - M.L. Taylor 5 Feb 1990
-- modified KABHaar 7 Nov 1990
-- modified KABHaar 5 Feb 1991
--
--
-- Requires that the user enter an organization number for each employee
-- and that the number be that of a previously-entered organization.
--
--
-- CALLING SEQUENCE -
--
-- Add_Employee;
--
-- ENTRY -
--
-- EXIT -
--
begin

Sage.ReadRecordR ("Org", "OrgNum", Sage.EQ, "Employee", "OrgNum");
if Sage.SageError = 0 then
Sage.WriteRecord ("Employee");
Display_Edit_Message ("added");
else
Display.DisplayMessage ("Bad organization # - record not added", true);
end if;

end Add_Employee;



procedure Modify_Employee is
--*
-- Modify_Employee
--
-- Author - M.L. Taylor 5 Feb 1990
-- modified KABHaar 7 Nov 1990
-- modified KABHaar 5 Feb 1991
--
--
-- Requires that the user enter an organization number for each employee
-- and that the number be that of a previously-entered organization.
--
--
-- CALLING SEQUENCE -
--
-- Modify_Employee;
--
-- ENTRY -
--
-- EXIT -
--
begin

Sage.ReadRecordR ("Org", "OrgNum", Sage.EQ, "Employee", "OrgNum");
if Sage.SageError = 0 then
Sage.ReWriteRecord ("Employee");
Display_Edit_Message ("modified");
else
Display.DisplayMessage ("Bad organization - record not modified", true);
end if;

end Modify_Employee;



procedure Delete_Employee is . . .


procedure Get_Next_Employee is . . .


procedure Get_Previous_Employee is . . .


procedure Locate_Employee is . . .


procedure Edit_Employee is
--*
-- Edit_Employee - Maintain the Employee relation
--
-- This procedure is used to perform all maintenance functions for the
-- Employee relation. Allowed maintenance functions are
--
-- Exit - close Employee relation and return to MainMenu
-- Add - add the currently displayed record
-- Modify - change the currently displayed record
-- Delete - delete the currently displayed record
-- Next - display the next employee in key sequence
-- Previous - display the previous employee in key sequence
-- Locate - display the employee with key GE on form
--
begin

Sage.OpenRelation ("Org", false);
Sage.OpenRelation ("Employee", true);

Sage.PutFieldA ("Utility", "A1", "E");

loop
Display.DisplayForm ("EmpEd", "Utility", "A1", false);
Sage.GetFieldA ("Utility", "A1", option);

case option (1) is

when 'E' => exit;

when 'A' => Add_Employee;

when 'M' => Modify_Employee;

when 'D' => Delete_Employee;

when 'N' => Get_Next_Employee;

when 'P' => Get_Previous_Employee;

when 'L' => Locate_Employee;

when others => Display.DisplayMessage ("Selected option unavailable", true);

end case;

end loop;

Sage.CloseRelation ("Employee");
Sage.CloseRelation ("Org");

end Edit_Employee;



procedure Edit_Organization is . . .


procedure Rebuild_All_Relations is . . .


procedure Browse_Employee is . . .


procedure Employee_Report is . . .


end HRS;




Go Back To Tutorial Table of Contents




warren.merrill@inl.gov , ftp://sage.inel.gov
Copyright © 1989-2006. Battelle Energy Alliance