Sage-ST ä Tutorial
Lesson 9


 
1. Overview.
In this lesson you will implement the Employee_Report procedure. This will be a very basic, one-line report that will be enhanced during subsequent lessons. Don't worry if some things don't work quite the way you might hope; just get the report to work.


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

Reports.OpenReport,
Reports.CloseReport,
Reports.WrForm,
Reports.FileRP,
Reports.DefineReport,
Files.FileState.


3. Assignment.
Create a header form in the THOR forms editor that includes the title of the report and the column headings. This form should probably only be four to five lines long and must be windowed so that only those lines necessary are included on the form.

Create a body form that includes display-only fields for each field you wish to show on the report. The fields should be properly positioned so that they appear centered below the column headings on the header form. Be sure that the fields you select to appear on the report all fit on one line. When you are finished defining and positioning the fields, window the line so that the body form is only one line long.

Now implement the Employee_Report procedure. The general idea is to open the relation and the report, write the header form, read the first record, and then do a loop of writing the body form and reading the next record until there are no more records to read. Be sure you close the report and the relation upon completion.

This report will scroll off the screen before you have a chance to read it unless you press <Pause>. It will start writing the report on top of whatever form is currently displayed, creating a rather messy effect. It also gives the user no options on where to send the report. These problems will be remedied in subsequent lessons.

Common problems on this lesson include


1. The report displays the header and a message at the bottom of the screen to press <E> to end, <Enter> to continue, but no data are ever displayed, nor will it let you break out of the report--you have to reboot. When you created your header form, you did not put it in a window, so the header takes up an entire page of the report. Because of the way the WrForm call is written, once Sage-ST detects that the bottom of the page has been reached, Sage-ST does a new page and writes the header--which takes up an entire page, so Sage-ST detects a bottom of page and . . . .

2. The report displays the header and one body per page. The body form has one line, but people frequently forget to window it, so it takes up an entire page.

3. The report does just fine, except that it keeps looping through the relation and printing out the report. Most likely you are checking your SageError in the wrong place.


4. Our Solution.

FORM REPORT FOR HRS

RptEmpB Employee report body 6 Field(s)
packed picture size -> 46 bytes
predominant color -> light cyan on black
-----------------------------------------------------------------------------



░░░░░1░░░░░ ░░░░░░░2░░░░░░░, ░░░░░░░3░░░░░░░ ░░░░░░░4░░░░░░░ 5░ ░░6░░




-----------------------------------------------------------------------------

Field Display Type Record & (Field) - rpt Field Type Help Form
-----------------------------------------------------------------------------
1 Display Only Employee(SSN) - 1 Social Security Number
2 Display Only Employee(LastNam) - 1 Alphanumeric
3 Display Only Employee(FirstNam)- 1 Alphanumeric
4 Display Only Employee(City) - 1 Alphanumeric
5 Display Only Employee(State) - 1 Upper Case Alphanumeric
6 Display Only Employee(Zip) - 1 Upper Case Alphanumeric




RptEmpH Employee report header 0 Field(s)
packed picture size -> 126 bytes
predominant color -> white on black
-----------------------------------------------------------------------------
EMPLOYEE REPORT
(sorted by employee SSN)

E m p l o y e e N a m e
SSN Last First City State ZIP




-----------------------------------------------------------------------------

with Display;
with Files ;
with ModSys ;
with Reports;
with Sage ;
with SageLib;
with Strings;


procedure HRS is
--*
-- HRS- Sage-ST training class Prototype 9 (GRAPL)
--
-- Author - M.L. Taylor 5 Feb 1990
-- modified KABHaar 7 Nov 1990
--
-- The goal of Prototype 9 is to produce a report of the Employee relation
-- which is sent to the console.
--
-- 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 . . .

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 . . .

procedure Browse_Employee 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 -
--

state : Files.FileState;
ftbl : Reports.FileRP;

error : ModSys.S_natural := 0;

begin

Sage.OpenRelation ("Employee", false);

Reports.OpenReport (ftbl, "CON", state);
Reports.DefineReport (ftbl, true, false, 24, false, false, 1);

Reports.WrForm (ftbl, "RptEmpH", "", "", true, error);

Sage.ReadRecord ("Employee", "SSN", Sage.First);

loop
Reports.WrForm (ftbl, "RptEmpB", "RptEmpH", "", true, error);
Sage.ReadRecord ("Employee", "SSN", Sage.Next);

-- exit when Sage.SageError /= 0;
-- GRAPL does not support the above notation
if Sage.SageError /= 0 then
exit;
end if;
end loop;

Reports.CloseReport (ftbl, state);
Sage.CloseRelation ("Employee");
end Employee_Report;

end HRS;


Go Back To Tutorial Table of Contents


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