S A M P L E   F O C E X E C S

Temporary Defines


Temporary data fields can be created using the define command and then used to create tables.

Three elements are needed:

       Name         - up to 12 characters
       Format       - if not specified, defaults to D12.2
       Expression   - the calculation to be performed, up to 40 lines,
                      terminated by a semi-colon

Syntax

       Define file snapshot add
       name/format = expression;
       end

For example, you can create a new field, annual gross, by
multiplying the monthly gross by 12.

       Define file snapshot add
       anngrs/Dl2.2=mongrs*12;
       end

Note:     Alphanumeric literals must be enclosed in single quotes,
          e.g. if chpppln is 'BC' then 'NEWPLAN' else 'HMO';

          Use parentheses to clarify compound expressions, e.g.
          cost = if (X is 'BQ' or 'BA') and  (Y is 'U') then 10 else 20;
Temporary defines remain in place throughout a session with the same file or until another define is used. If the word "Add" is used, the new defines do not replace the first, but are added to them. A temporary define can be erased by using the word "clear", instead of "add". All temporarily defined fields are erased when the change file (cf) command is used and at the end of the session when "fin" is typed.

Defined fields are located in the file at the lowest record segment needed to create the expressions. A define using appointment pay rate and monthly precent time would be stored at the distribution level and would be created in each distribution segment.

To determine which defined fields are currently available type:

REMEMBER: Always use "add" or you will lose the permanent defines

ARITHMETIC OPERATIONS

a.   Problem:  What is the annual gross pay by sex?

     >
     >
     define file snapshot add
     anngrs=mongrs*12;
     end
     >
     tfs
     sum anngrs by csex
     end

     NUMBER OF RECORDS IN TABLE=          1206   LINES=       2

     PAGE  1

     CSEX         ANNGRS
     ----         ------
     F      6,159,030.00
     M      7,313,719.44


b.   Problem:  By campus calculate the cost of two different bonuses for
     persons represented by the clerical unit.  Bonus A is the monthly
     gross plus 5%.  Bonus B is the monthly gross plus 10%. This
     applies to basic pay only (cdos=am, av, aw or ax).

     >
     define file snapshot  add
     bonusA=mongrs*.05+mongrs;
     bonusB=mongrs*.l+mongrs:
     end
     >
     tfs
     sum bonusA bonusB
     by campus
     if tuc is cx
     if captrep is c
     if cdos is av or am or aw or ax
     on table column-total
     end

     NUMBER OF PFRORDS IN TABLE=          158    LINES=      9

     PAGE    1

     CAMPUS         BONUSA      BONUSB
     ------         ------      ------
     BK          53,601.86   56,154.33
     DV          19,501.70   20,430.35
     IR          24,073.69   25,220.05
     LA          51,683.36   54,144.47
     RV          10,754.85   11,266.98
     SB           8,802.54    9,221.71
     SC           2,012.19    2,108.01
     SD          14,025.51   l4,693.39
     SF          30,984.90   32,460.37

     TOTAL      215,440.60  225,699.67
LOGICAL OPERATIONS
c.   Problem:  Classify employees as to whether they are on
     northern or southern campus.


>
define file snapshot add
xcampus/a5=if campus is 'BK' or 'SF' or 'DV' or 'SC' then 'north'
  else 'south';
end
>
tfs
count empno by xcampus
end

NUMBER OF RECORDS IN TABLE=   848  LINES=      2

PAGE     1

         EMPNO
XCAMPUS  COUNT
-------  -----
NORTH    464
SOUTH    384


d.   Problem:  Count employees in four groups: (a) all males (b) females
     less than 20 (c) females age 21 or 22 (d) everyone else.


define file snapshot add
group/a7=if csex is 'm' then 'group_a' else
if csex is 'f' and age it 20 then 'group b' else
if (csex is 'f') and (age is 21 or 22) then 'group_c' else
'group_d';
end
>
tfs
count empno by group
end

NUMBER OF RECORDS IN TABLE=       807 LINES=      4

PAGE         1

         EMPNO
GROUP    COUNT
-----    -----
GROUP-A    379
GROUP-B     25
GROUP-C     35
GROUP-D    368

Back to Sample Focexecs