|
|
Sage-ST
ä
Tutorial
|
1. Overview.
In this lesson you will switch over to the Ada compiler.
2. What You'll Use.
You will use your text editor and the Ada compiler.
3. Assignment.
Due to the limitations of GRAPL, several portions of the code are not as concise as they could be. Since you will no longer be using GRAPL, the work-arounds are no longer necessary: all valid Ada constructs may be used. Go back through your code and clean it up.
Create a new library where you can compile your system (there may be a batch file called MAKELIB.BAT in your Ada directory). Compile your code (batch file called AD.BAT in Ada directory; however, you will need to change the library name). After a successful compilation, bind the main procedure (batch file called BD.BAT). To execute, type in the name of your main procedure--HRS. Test thoroughly to be sure everything still works.
Some people do not like using batch files; however, for classroom purposes batch files are convenient and easy to use. Because our mission does not include Ada or compiler-specific instruction; the batch files eliminate the need to discuss these subjects. If you have extra time, experiment with your system and the various compiling and binding options available.
4. Our Solution.
with Display ;
with Files ;
with ModSys ;
with Reports ;
with Sage ;
with SageLib ;
with Strings ;
with ThorPort;
procedure HRS is
--*
-- HRS- Sage-ST training class Prototype 13 (GRAPL)
--
-- Author - M.L. Taylor 5 Feb 1990
-- modified KABHaar 7 Nov 1990
--
-- The goal of Prototype 13 is to convert HRS.GPL to Ada.
--
-- Convert all code to take advantage of Ada's power, change the GPL extension
-- to ADA, and compile using the Ada compiler.
--
--
-- CALLING SEQUENCE -
--
-- GRAPL HRS
--
-- ENTRY -
--
-- EXIT -
--
option : string (1..1) := (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 -
--
begin
if Sage.SageError = 0 THEN
Display.DisplayMessage ("Record " & operation, false);
else
Display.DisplayError (Sage.SageError, true);
end if;
end Display_Edit_Message;
procedure Add_Employee is . . .
procedure Modify_Employee is . . .
procedure Delete_Employee is . . .
procedure Get_Next_Employee is . . .
procedure Get_Previous_Employee is . . .
procedure Locate_Employee is . . .
procedure Edit_Employee is . . .
procedure Edit_Organization is . . .
procedure Rebuild_All_Relations is
--*
-- Rebuild_All_Relations
--
-- This procedure will rebuild the indexes of all the relations in the HRS
-- database.
--
--
emp_Rebuilt : boolean := false;
org_Rebuilt : boolean := false;
num_Of_Duplicates : ModSys.S_long_integer := 0;
begin
Sage.OpenRelation ("Employee", true);
Display.DisplayMessage ("Rebuilding employee index", false);
Sage.RebuildIndex ("Employee", true, num_Of_Duplicates);
emp_rebuilt := (Sage.SageError = 0);
Sage.CloseRelation ("Employee");
Sage.OpenRelation ("Org", true);
Display.DisplayMessage ("Rebuilding Organization Index", false);
Sage.ReBuildIndex ("Org", false, num_Of_Duplicates);
org_Rebuilt := (Sage.SageError = 0);
Sage.CloseRelation ("Org");
if emp_Rebuilt and org_Rebuilt then
Display.DisplayMessage ("Rebuild of HRS data base complete", false);
else
Display.DisplayMessage ("Portions of the rebuild were not successful.", true);
end if;
end Rebuild_All_Relations;
procedure Browse_Employee is . . .
procedure Get_File_Name (fName : in out string) is . . .
procedure Employee_Report is
--*
-- Employee_Report - Generate simple employee report.
--
-- KABHaar, 7 November 1990
--
-- The Sage-ST reports package can be used to fulfill the reporting
-- requirements for most applications. The format and actual field contents
-- of the report are separated from the application code by using THOR forms.
-- Once the logic is in place to assemble the desired records, changes in
-- report format and content can often be made without code changes. This
-- example prints the Employee records in SSN order.
--
-- CALLING SEQUENCE -
--
-- Employee_Report;
--
-- ENTRY -
--
-- EXIT -
--
success : boolean := false;
newPage : boolean := false;
state : Files.FileState;
ftbl : Reports.FileRP;
error : ModSys.S_natural := 0;
lines_Per_Page : ModSys.S_natural := 55;
file_Name : string (1..30) := (others => ascii.nul);
begin
Sage.OpenRelation ("Employee", false);
Get_File_Name (file_Name);
ThorPort.ClearScreen;
Reports.OpenReport (ftbl, file_Name, state);
if file_Name (file_Name'first..file_Name'first+2) = "CON" then
lines_Per_Page := 24;
end if;
Reports.DefineReport (ftbl, true, false, lines_Per_Page, false, false, 1);
Reports.WrForm (ftbl, "RptEmpH", "", "", true, error);
Sage.ReadRecord ("Employee", "SSN", Sage.First);
while Sage.SageError = 0 loop
Reports.WrForm (ftbl, "RptEmpB", "RptEmpH", "", true, error);
Sage.ReadRecord ("Employee", "SSN", Sage.Next);
if Sage.SageError /= 0 then
while (Reports.RemainingLines (ftbl) >= 1) and (not newPage) loop
Reports.WrLn (ftbl, newPage);
end loop;
exit;
end if;
exit when Reports.ConsoleTerminate;
end loop;
Reports.CloseReport (ftbl, state);
Sage.CloseRelation ("Employee");
end Employee_Report;
end HRS;
Go Back To
Tutorial Table of Contents