Sage-ST ä Tutorial
Lesson 22



1. Overview. In this lesson, within the EditPack package you will modify your Employee relation so that written evaluations on employee performance can be stored and accessed.


2. What You'll Use.
You will use the following new Sage-ST call:

BlkEdit.Block_Data_Editor.


3. Assignment.
Using THOR, add the field "Eval" to the Employee relation. This field should be a Type 12 field. Its length is fixed at 4 bytes, and it will default to this value regardless of what you type in. Go into the file editor and modify the employee file set to include "EMPLOYEE.BLK" in which variable length data can be stored. Because you have changed the schema, you must rebuild the Employee relation.

The data stored in the Eval field is an address to a location in the EMPLOYEE.BLK file; the actual text is NOT stored in this field. You will, therefore, be working with access types (pointers).

On the ScrlEmp form, add the option "eValuation". It will not be necessary to design any forms for editing the data. The editor that will be used will create its own editing window. During the editing process the user will be able to:

<Del> -- delete a character
<Ins> -- insert a character
<Alt/A> -- add a line
<Alt/D> -- delete a line
<Alt/B> -- block text for copying or moving
<Alt/R> -- restore a deleted line
<Alt/S> -- split a line
<Alt/J> -- join two lines
<Alt/H> -- call a help screen showing available commands
<Ctrl/End> -- erase to end of line
<Esc> -- abort out, do not save
<Alt/E> -- save and exit

Other commands are also available and may be seen in the editor by pressing the help key (<F1>). This editor call takes care of getting the current block data contents and saving it again when the user exits.

When calling the edit routine the following parameters are passed:

Relation: Name of the relation containing the variable length data field;


Field: Name of the variable length data field;

Line_Length: Length of the line while editing. This can be larger than the actual size of the window (default window is 80). If it is larger, the editor will allow left and right scrolling to see the line;

Modify: This flag tells the editor whether it should allow modification of the data that is being viewed;

Defaults: If this flag is true, the editor will use its own default values for the colors, editing keys, and window size. If you desire to change any of the default values then you should make the appropriate calls to the TextEdit routines to modify these values and call Block_Data_Editor with this flag set to false;

Header: If you want to use your own header, create the header form using THOR, do a Display.DisplayBackground just before the Block_Data_Editor call, and set this parameter to FALSE. If you want to use the header provided by BlkEdit, set this to TRUE.

Print_Dest: If you want to allow the user to do a "hot key" print while editing the text, pass in a value here that represents where the output is to go (e.g. "PRN" for a printer, "PRINT.OUT" for a file, etc.). If a null string is passed for this parameter, the user will not be allowed to do printing from within the editor;

Print_Key: If you have set Print_Dest to true and want to specify the key to use for printing, enter that key as a two-unsigned_byte sequence (e.g., "F7"). If two zeros are passed in for this parameter, the Block_Data_Editor will use the default key. This parameter MUST be two and only two unsigned_bytes long.

At the time you implemented your load and unload, there was no variable length data field. This address cannot be simply written to an ASCII file. In order to transfer variable length data to another data base, the actual text must be retrieved into the code and then written to the file. BufIO is used in this, along with Sage.PutBlock and Sage.GetBlock. This is covered in the advanced class.


4. Our Solution.



RECORD REPORT FOR HRS



Record Name: Employee
Description : individual employee records
Fields : 11
Byte Length : 89
File Number : 1
Data File : EMPLOYEE.DAT
Index File : EMPLOYEE.IDX
Block File : EMPLOYEE.BLK

Field Name Description/Type Length Key Type Sub-Fields Repeat Decimals
-----------------------------------------------------------------------------

Eval employee evaluation 4 Non-keyed 1
12 (Variable Block Data)



BrowseO Outer scroll editor for employ 1 Field(s)
packed picture size -> 483 bytes
predominant color -> light red on black


---------------------------------------------------------------------------------------------------------------------
B r o w s e E m p l o y e e R e l a t i o n

 

 

 

 

 


<F2> - Add Employee, <F3> - Modify Employee, <F4> - Delete Employee
<F5> - Edit Evaluations
----------------------------------------------------------------------------------------------------------------
Field Display Type Record & (Field) - rpt Field Type Help Frm
----- ------------- ---------------------- ------------------------------------------------------------- --------
1 Display Only Utility (String) - 1 Alphanumeric

 

 

with BlkEdit ;
with Display ;
with ModSys ;
with Sage ;
with SageLib ;
with Strings ;
with TextEdit;


package body EditPack is


option : string (1..1) := (others => ascii.nul);


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

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 Load_Record_In_Form(recNum : in out ModSys.S_long_integer;
entryForm : in boolean;
searchString : in out string) is

--*
-- Load_Record_In_Form - ScrollForm's RecordToForm Procedure
--
-- Loads in an employee record by record number on SSN key
--
-- D.H. Schwieder - 02/22/93
--
-- See Display.ScrollForm for descriptions of parameters.
--

SSN_string : string(1..11) := "000-00-0000";
offset : ModSys.S_natural := 0;

begin

if (recNum > 0) then -- A record is requested. Read it.

Sage.ReadRecordN ("Employee", "SSN", recNum);
if (Strings.Length(searchString) = 0) then
Sage.ClearField ("Utility", "String");
end if;

elsif ((Strings.Length(searchString) > 0) and
(Strings.Length(searchString) < 10)) then

for index in 1..Strings.Length(searchString) loop
if index > 3 then
offset := 1;
end if;
if index > 5 then
offset := 2;
end if;
SSN_string(index + offset) := searchString(index);
end loop;

Sage.PutFieldA ("Utility","String", SSN_string);
Sage.ReadRecordA ("Employee", "SSN", Sage.GE, SSN_string);
if (Sage.SageError = 0) then
Sage.GetKeyPosition ("Employee", "SSN", recNum);
else
Display.DisplayError (Sage.SageError, true);
recNum := 0;
Strings.NulFill ("",searchString);
Sage.ClearField ("Utility", "String");
end if;

end if;

Display.DisplayBackground ("BrowseO", false);

end Load_Record_In_Form;


procedure Process_Record_In_Form (recNum : in out ModSys.S_long_integer;
changed : in boolean;
refresh : in out boolean;
exitProc : in out boolean;
recTot : in out ModSys.S_long_integer) is

--*
-- Process_Record_In_Form - ScrollForm's FormToRecord Procedure
--
-- Processes changed employee records by rewriting record.
--
-- D.H. Schwieder - 02/22/93
--
-- See Display.ScrollForm for descriptions of parameters.
--

lastExit : ModSys.S_natural := 0;
key : TextEdit.Key_Type := (1 => 0, 2 => 0);

begin

if (changed) then
Sage.ReWriteRecord("Employee");
refresh := true;
end if;

lastExit := Display.LastExitFunction;

case lastExit is

when 41 => -- Add a new employee
Sage.ClearRecord ("Employee");
Display.DisplayForm ("AddEmp", "Employee", "SSN", false);
Sage.WriteRecord ("Employee");
if (Sage.SageError = 0) then
Display.DisplayMessage ("Employee record added.",false);
recTot := recTot + 1;
else
Display.DisplayMessage ("Error in adding record.",true);
end if;
refresh := true;

when 42 => -- Modify employee record
Display.DisplayForm ("ModEmp", "Employee", "SSN", false);
Sage.RewriteRecord ("Employee");
if (Sage.SageError = 0) then
Display.DisplayMessage ("Employee record modified.",false);
else
Display.DisplayMessage ("Error in modifying record.",true);
end if;
refresh := true;

when 43 => -- Delete employee record
Sage.DeleteRecord ("Employee");
if (Sage.SageError = 0) then
Display.DisplayMessage ("Employee record deleted.",false);
recTot := recTot - 1;
else
Display.DisplayMessage ("Error in deleting record.",true);
end if;
refresh := true;

when 44 => -- edit evaluation field
BlkEdit.Block_Data_Editor
("Employee", "Eval", 80, true, true, true, "", key);

if BlkEdit.Editor_Saved then
Sage.ReWriteRecord ("Employee");
if Sage.SageError = 0 then
Display.DisplayMessage ("Record text modified.", false);
else
Display.DisplayMessage ("Error modifying text.", false);
end if;
end if;

when others => -- do nothing
refresh := false;

end case;

end Process_Record_In_Form;



procedure Employee_Scroll is new Display.ScrollForm
(Load_Record_In_Form,Process_Record_In_Form);


procedure Browse_Employee is

--*
-- Browse_Employee - Browse and edit Employee relation
--
-- This procedure displays a portion of the employee relation. User
-- can scroll through the relation and change fields if desired.
--
-- D.H. Schwieder - 02/22/93
--


recPos : ModSys.S_long_integer;
recTot : ModSys.S_long_integer;

begin
Sage.OpenRelation ("Employee", true);

Sage.ClearField ("Utility", "String");
recPos := 1;
recTot := Sage.TotalRecords("Employee");
Employee_Scroll("BrowseO", "BrowseC", "BrowseI", recPos, recTot);

Sage.CloseRelation ("Employee");

end Browse_Employee;

end EditPack;

 


Go Back To Tutorial Table of Contents


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