|
|
Sage-ST
ä
Tutorial
|
1. Overview. In this lesson you will check for errors that may occur during the editing operations and display a message to the user indicating the success or failure of the operation.
2. What You'll Use. You will use your text editor and GRAPL. The following new Sage-ST calls will be used:
Sage.SageError,
Display.DisplayError.
See Volume 2 for the description of Sage.SageError.
3. Assignment. After a call to any Sage or Display procedure, a global variable, SageError, is set indicating the status of the operation. If SageError is 0, the operation was successful; if SageError is not 0, the operation was not successful. (See the Sage-ST User Manual for a complete listing of SageErrors). When performing reads, writes and rewrites it is a good idea to check SageError to see whether or not the operation was actually performed. For Lesson 6 use Display.DisplayMessage and Display.DisplayError to inform the user of the outcome. Enter data for at least six employees.
At times there will be specific errors which you will look for. For example, if you are nexting through a relation and want to know when you have hit the end of the file, a ReadRecord (...Sage.Next) which returns a SageError of 112 means that the end of file has been reached.
Although any procedure in Sage or Display can reset the SageError, some procedures are very unlikely to return a SageError other than 0. One example of this is GetFieldA. As long as the string into which you are getting the data is large enough to accommodate the field, GetFieldA will set the SageError to 0. If the relation is closed, GetFieldA is successful because it is accessing the memory record, not the actual file. If no record has been read and the field is empty, GetFieldA is successful because it simply gets a null string from the field.
4. Our Solution.
with Display;
with Sage ;
with SageLib;
with Strings;
procedure HRS is
--*
-- HRS - Sage-ST training class Prototype 6 (GRAPL)
--
-- Author - M.L. Taylor 5 Feb 1990
-- modified KABHaar 7 Nov 1990
--
-- The goal of Prototype 6 is to use SageError to check for potential
-- problems and display appropriate messages to the user.
--
-- 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
--*
-- Display_Edit_Message - notify user of success or failure of operation
--
-- Author - M.L. Taylor 5 Feb 1990
-- modified KABHaar 7 Nov 1990
--
-- The user passes in a word describing the operation being attempted,
-- usually "added", "modified", "deleted", or "found". If the operation
-- was successful and Sage.SageError is zero, this word will be used in
-- the phrase "Record <string>". If the operation was not successful,
-- Display.DisplayError is used to display an error message.
--
--
-- CALLING SEQUENCE -
--
-- Display_Edit_Message ("added"); OR
-- Display_Edit_Message ("modified"); OR
-- Display_Edit_Message ("deleted");
--
-- ENTRY -
--
-- operation : string defining the attempted operation.
--
-- EXIT -
--
success : boolean := false;
message : string (1..20); -- not supported by GRAPL := (others => ascii.nul);
begin
if Sage.SageError = 0 THEN
Strings.Concat ("Record ", operation, message, success);
Display.DisplayMessage (message, false);
else
Display.DisplayError (Sage.SageError, true);
end if;
end Display_Edit_Message;
procedure Add_Employee is
begin
Sage.WriteRecord ("Employee");
Display_Edit_Message ("added");
end Add_Employee;
procedure Modify_Employee is
begin
Sage.ReWriteRecord ("Employee");
Display_Edit_Message ("modified");
end Modify_Employee;
procedure Delete_Employee is
begin
Sage.DeleteRecord ("Employee");
Display_Edit_Message ("deleted");
end Delete_Employee;
procedure Get_Next_Employee is
begin
Sage.ReadRecord ("Employee", "SSN", Sage.Next);
if Sage.SageError /= 0 then
Sage.ReadRecord ("Employee", "SSN", Sage.First);
Display.DisplayMessage ("First record", false);
end if;
end Get_Next_Employee;
procedure Get_Previous_Employee is
begin
Sage.ReadRecord ("Employee", "SSN", Sage.Previous);
if Sage.SageError /= 0 then
Sage.ReadRecord ("Employee", "SSN", Sage.Last);
Display.DisplayMessage ("Last record", false);
end if;
end Get_Previous_Employee;
procedure Locate_Employee is
begin
Sage.ReadRecord ("Employee", "SSN", Sage.GE);
Display_Edit_Message ("found");
end Locate_Employee;
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 ("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");
end Edit_Employee;
procedure Edit_Organization is
--*
-- Edit_Organization - Maintain the Org relation
--
-- This procedure is used to perform all maintenance functions for the
-- Organization relation. RecordEdit provides a complete editor. Allowed
-- maintenance functions are
--
-- Exit - close Org 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.PutFieldA ("Utility", "A1", "E");
SageLib.RecordEdit ("OrgEd", "Org", "OrgNum", "Utility", "A1");
end Edit_Organization;
procedure Rebuild_All_Relations is . . .
procedure Browse_Employee is . . .
procedure Employee_Report is . . .
end HRS;
Go Back To
Tutorial Table of Contents