Understanding Rules

This section discusses:

  • General setup steps.

  • Rules from actions and conditions and SQL objects.

  • Rule step creation guidelines.

All rules in Time and Labor are written in SQL. You don't have to be a SQL expert to create rules because you will probably create most rules using templates, and the templates contain the basic logic, underlying structures, and necessary SQL objects. However, an understanding of SQL is helpful, particularly if you use actions and conditions, or SQL objects to define your rules, since these tools give direct access to SQL logic and language. In addition, to properly create, test, and troubleshoot rules, you should understand the structure of a SQL statement and the basic procedures for converting business rules into SQL rules.

Perform these two setup steps before creating rules if you are using either actions and conditions, or SQL objects to define the rules:

  • Specify which tables (or records) to access and which SQL actions rule's developers can access.

    You'll do this using the Working Tables page.

  • If you create a condition that references a field that is not part of the record being updated, define a relationship definition (or join) between the record you are updating and the external record.

    To do this, use the TL Relationship Definitions page. Setting up a relationship definition eliminates the need to code this relationship. If you are creating rules using actions and conditions, set up this relationship definition beforehand (if you must refer to external tables). You cannot define a table join within the rule itself. If you are using SQL objects, create a table join directly in the rule.

When you use the Actions and Conditions or the SQL Objects pages, you won't create complete rules, but the building blocks of rules: rule components. To define a complete rule, you must:

  • Link the components to other components.

  • Place the components in the proper order for processing (define rule steps).

  • Specify the period of interest for the resulting rule.

  • Group rules into rule programs and then link these rules to time reporters through workgroups.

Note: Template-built rules are fully defined rules. This means that you don't need to define the rule steps that make up a template-built rule. However, you do need to add template-built rules to rule programs on the Rule Programs page, and assign the rule program to a workgroup.

To complete a rule definition:

  1. Define the rule components.

    Use Actions and Conditions or SQL Objects.

  2. Define the rule period.

    Specify the period of interest for the rule using the Define Rule Header page. Valid periods include PeopleSoft-delivered periods and any time periods created using the Time Period pages. The system uses time periods to determine the data for a particular span of time on which the rule will act. The Time Administration program also uses the time period to determine which reported time to load into the working tables during processing.

  3. Define rule steps.

    Once you define the individual building blocks that make up a rule using actions and conditions or SQL objects, you must combine these components into complete rules and place them in the correct processing order by arranging them into rule steps. Each rule can have one or multiple steps. You'll order individual rule components into rule steps on the Define Rule Steps pages. SQL processes the records in sets. Rule steps must be properly ordered for set processing. Review delivered rule templates (with the rule ID prefix of TEMPLATE) to see how rule steps are organized for set processing. Test the SQL statement for each rule step with the database query tool to ensure that it produces the desired results before continuing with the next step. You may need to replace meta-SQL with platform–specific SQL before testing the SQL statement.

  4. Assign the rule to a rule program.

    Add your rules to a rule program using the Rule Program and Program Detail pages. The rule program specifies the set of rules and the order in which the Time Administration process executes them.

    Note: The number of online rules you can include in a rule program is determined by the entry in the Maximum Online Rules field on the TL Installation page.

    Note: Rule programs are effective-dated, but the individual rules contained within them are not. You cannot modify a rule once you assign it to a rule program. However, you can remove the rule from the rule program and replace it, if appropriate, with a new rule. This feature ensures the referential integrity of rules processing.

  5. Attach the rule program to a workgroup.

    Use the Workgroup page. The rule program determines which rules are processed for the time reporters in the workgroup. If a rule does not exist in the rule program associated with a workgroup, no member of the workgroup is processed using that rule.

When you create rules in Time Administration, you translate the organization's business rules into SQL statements for the system. The Time Administration pages enable you to implement rules, but they are not design tools. Before you enter any information in these pages, design and organize your rule steps, consider the SQL involved, and decide which Time Administration options to use. This section provides guidelines for understanding, designing, and organizing rule steps. The end of this section provides an example that outlines more explicitly how to enter rule steps into the system.

Note: Use the simplest building blocks when creating rules. Whenever possible, use or modify the delivered rule templates rather than creating new actions and conditions or SQL objects to define rules.

Design and Organize Rule Steps

Determine whether you can use one of the delivered rule templates or if you must create either actions and conditions or SQL objects. Consider which rules or parts of rules to reuse. If you can use part of a rule repeatedly or in many ways, create an action or condition or a SQL object so that you can reuse that part of the rule.

Think about dependencies: what should be checked or processed first. If you want to act on a subset of data or the results of a query, define that data or subquery first. If you want to act only if a certain condition exists, create the statement to determine if the condition is true before inputting the action. If you want to perform multiple actions on a single row, think about processing order. For example, if you must compare daily reported time to daily scheduled hours, sum the daily reported time and scheduled time first. Although the comparison and summation could be a single step, keep each step relatively simple for maintenance and troubleshooting. Specify and order rule steps on the Define Rule Steps page.

Avoid broad or redundant querying or processing. For optimal performance, create conditions that retrieve the fewest possible records and still satisfy your data needs. For example, specifying certain column names in your Select statements is more efficient than selecting all columns. Use the logical operator IN instead of OR, since IN is processed faster than OR.

If you want to create a rule that concerns a certain period of time, define a valid rule period ID for that rule.

Use all the tools available to you. When possible, use PeopleSoft-delivered objects. Create value lists instead of multiple conditions. Several working tables are delivered within rules, but you can create your own working tables. They must be temporary tables.

Warning! Do not modify delivered working tables. If any of the delivered working tables are modified, template-built rules do not function properly and may generate unexpected results. Also consider copying delivered SQL objects into your own, using your individual naming prefix. This ensures that your rules are affected by future, delivered, modifications to SQL objects.

Translate Business Rules into SQL Rules

Before you create rules in Time and Labor, have a clear idea of how you manage both time and time reporters, and have the business rules in front of you when you begin. Certain terminology in these documents has counterparts in particular SQL conditions and actions. Words such as update, replace, and substitute frequently imply the SQL action update. Words such as where, if, when, and in case of imply dependencies and conditions.

Use Working Tables within Rules

Before Time Administration can execute a rule, it moves the time reporter data needed to run the rule from scheduled and reported time into a data store known as Intermediate Payable Time. Rules are applied to information in the data store rather than to data in scheduled or reported time to protect the integrity of the source data. The Intermediate Payable Time data store comprises these five tables:

  • TL_IPT1

  • TL_IPT2

  • TL_IPT3

  • TL_IPT4

  • TL_IPT5

In addition to the Intermediate Payable Time tables, you can access a number of other working tables in the system. Most of these working tables start with the prefix TL_WRK.

Note: You can create your own working tables to store data temporarily, but they must be temporary tables.

Rules for Using Working Tables

When you create rules in Time Administration, remember that:

  • Time Administration automatically loads much of the data for executing rules into the Intermediate Payable Time table TL_IPT1.

    In the rules, you can move data back and forth between this table and the other Intermediate Payable Time tables. For example, the rule can move time data from TL_IPT1 to TL_IPT2, apply a specific TRC to this time, and then update the original row of data in TL_IPT1 with the new TRC-associated data.

  • You must decide when and how to move data from TL_IPT1 to other working tables.

    After the rules process and modify the data in other tables, return any processed data to send to Payable Time back to TL_IPT1, which is the table containing the original, raw data. That is, push the data in its final form—the form in which to the data to Payable Time—back to TL_IPT1. If the data does not exist in TL_IPT1, it will not become part of Payable Time.

  • You must always truncate (or clear) working tables before moving data into them.

    This ensures that the data that remains in those tables from previous rules processing does not interfere with or corrupt the new data. To truncate any working table, use the %TruncateTable command, which is included in the list of meta-SQL commands supported by PeopleSoft. However, never truncate or delete the data in TL_IPT1; it contains raw time data to execute the rules. If you delete this data, the rules have nothing to process.

  • You can move data from external tables (nonworking tables) into working tables.

    If you do not plan to process or modify this data, but you must verify it (in a condition statement, for example), consider reading the external tables directly rather than moving large quantities of information into the working tables. Moving large quantities of data into TL_IPT1 can affect processing speed.

Example: Translating Business Rules into SQL Rules

This example illustrates how to translate a business rule into a SQL rule, and how the resulting SQL rule moves data from TL_IPT1 to other working tables in the system. Suppose that your business rule states: All hours worked in excess of 40 hours in any one week shall be paid at the rate of 1.5 times the employee's applicable hourly rate.

The first step is to rewrite the business rule in a simpler sentence. If possible, translate business concepts into Time and Labor terms. For example, you recognize that the rate of 1.5 times the normal rate implies a different (overtime) TRC. Rewrite this business rule as: Replace all hours in excess of 40 in a week with TRC OT 1.5.

Next, determine what type of action the system will take. Most business rules require an insert or update and may require subqueries to determine more precisely which rows to affect. This example requires the update action.

Note: If your business rules require you to store the original rows and add rows only where the TRC changes, you would create an insert action.

Next, consider what conditions exist in the statement. In our example, in excess of 40 hours and in one week are conditions.

To accomplish this rule, you need seven steps. Steps one through two are actions; steps three through seven are SQL objects:

  1. Delete TL_IPT2 (truncate working table).

  2. Delete TL_IPT3 (truncate working table).

  3. Insert affected row (Friday, 10, 46, REG) into TL_IPT2 with hours over threshold and new TRC.

  4. Insert rows after affected row (Saturday, 6, 52, REG) into TL_IPT3.

  5. Calculate TL_QTY-TL_QTY in work record (TL_IPT2) and update row (Friday, 10, 46, REG becomes Friday, 4, 40, REG) in TL_IPT1.

  6. Insert new row (Friday, 6, 46, OT1.5) into TL_IPT1 with new sequence number.

  7. Update TL_IPT1 TRC with 'ot1.5' where exists in TL_IPT3.

The shaded rows in these tables represent Intermediate Payable Time created by these rule steps. Changes to the original TL_IPT1 data are in italics:

Data in IPT1

This table lists the data in IPT1:

Day

Hours

Total Week Hours

TRC

Monday

8

8

REG

Tuesday

10

18

REG

Wednesday

8

26

REG

Thursday

10

36

REG

Friday

10

46

REG

Saturday

6

52

REG

Data in IPT2

This table lists the data in IPT2:

Day

Hours

Total Week Hours

TRC

Friday

4

40

REG

Friday

6

46

OT 1.5

Data in IPT3

This table lists the data in IPT3:

Day

Hours

Total Week Hours

TRC

Saturday

6

52

OT 1.5

Data in IPT1 After Processing

This table lists the data in IPT1 after processing:

Day

Hours

Total Week Hours

TRC

Monday

8

8

REG

Tuesday

10

18

REG

Wednesday

8

26

REG

Thursday

10

36

REG

Friday

4

40

REG

Friday

6

46

OT1.5

Saturday

6

52

OT1.5

Note: This simple example ignores the TRC. A more complicated example could also include a daily rule run before this and might also create overtime.

Using Value Lists within Rules

When you want the condition or action clause of a rule to apply to multiple values—such as multiple TRC codes, multiple shifts, or multiple task groups—create value lists rather than defining multiple conditions.

For example, you have a rule that tells the system to create premium time when a time reporter reports more than 40 hours to time reporting codes Regular, Sick, Vacation, and Holiday. Before you create this rule, you set up a TRC value list and add the TRCs for Regular, Sick, Vacation, and Holiday. When Time Administration executes the rule, it will refer only to the four TRCs in your list. For another example, you want to restrict the punch types that can follow an In punch. You can create a value list that includes only those punch types you deem valid. You can then use Rule Template240 to create a rule that generates an exception when an invalid punch type follows an In punch. Value lists are used within template-built rules.

This table shows each type of list you can create and where the values are defined:

Type of Value List

Where Values Are Defined

Companies

PS_COMPANY_TBL

Dept IDs

PS_DEPT_TBL

Employee Statuses

Translate Values for EMPL_STATUS

Employee Types

Translate Values for EMPL_TYPE

Grades

PS_SAL_GRADE_TBL

Jobcodes

PS_JOBCODE_TBL

Paygroups

PS_PAYGROUP_TBL

Position numbers

PS_POSITION_DATA

Punch Types

Translate Values for PUNCH_TYPE

Steps

PS_SAL_STEP_TBL

Shifts

PS_SCH_SHIFT_TBL

TCD Groups

PS_TL_TCDGRP_TBL

Taskgroups

PS_TL_TASKGRP_TBL

TRCs

PS_TL_TRC_TBL

Union Codes

PS_UNION_TBL

Workgroups

PS_TL_WRKGRP_TBL

Rule Elements within Rules

To control how and when rules are applied to different groups of time reporters, use rule elements. You can define up to five rule elements to represent any type of data, and then use these elements within the conditions for your rules.

Rule elements are associated with time reporters by:

  • Assigning rule elements directly to time reporters on the Create Time Reporter Data page or the Maintain Time Reporter Data page.

  • Positively reporting rule elements when entering time.

Example: Defining and Using Rule Elements

You define a rule element called Jobs. You also create these values for Jobs: HOST, CASHIER, ASST MGR, WAITER. Next, you build a rule that creates a premium if a worker positively reports the value ASST MGR for rule element 1. As an alternative, you might build your rule so that the system creates a premium whenever time is reported by a person for whom the value ASST MGR is entered in the Rule Element 1 field on the Create Time Reporter Data page or the Maintain Time Reporter Data page.

Note: Both the Time Reporting Template page and the Rapid Time Template page include options to override rule elements.

Meta-SQL within Rules

Use meta-SQL as an alternative to creating complex SQL commands on your own. Meta-SQL enables you to perform many SQL functions by giving you access to complex SQL operations in a shorthand form. Meta-SQL functions expand to platform-specific SQL statements. Time and Labor uses meta-SQL to interface with different database platforms. A meta-SQL operand begins with a percent (%) sign and returns a scalar value. Almost all meta-SQL constructs that are visible in Time and Labor are PeopleTools meta-SQL constructs that are processed at run time.

Common HR Data in Rules

To use Human Resources or Time and Labor employee data within your rules, check whether the data exists in TL_PROF_WRK before creating multiple joins to tables in Human Resources. TL_PROF_WRK is a temporary table created at the beginning of the Time Administration batch run. It contains employee-related data retrieved from various HCM and Time and Labor source tables, effective as of the current run. Instead of accessing the various source tables to create a rule, you can create a single join to this table to retrieve information relating to all the time reporters you must process.

Warning! Do not alter the structure of TL_PROF_WRK. Time Administration references this table at different times during the batch run. If you need field values that are not present in TL_PROF_WRK, it is better to create a new record that stores those values, and insert one row for each effective dated row in TL_PROF_WRK. This protects you from any future delivered changes in this area, and means that you will not need to perform custom maintenance on the SQL statements loading TL_PROF_WRK.

TL_PROF_WRK contains fields derived from these source tables:

#

Field Name

Source

Description

1

EMPLID

TL_EMPL_DATA

Employee identification number.

2

EMPL_RCD

TL_EMPL_DATA

Employee record number.

3

NAME

PERSONAL_DATA

Employee name.

4

EFFDT

BADGE_TBL

Effective date of the badge.

5

BADGE_NBR

BADGE_TBL

Badge number.

6

HIRE_DT

EMPLOYMENT

Hire date.

7

REHIRE_DT

EMPLOYMENT

Rehire date.

8

CMPNY_SENIORITY_DT

EMPLOYMENT

Seniority date.

9

SUPERVISOR_ID

EMPLOYMENT

Supervisor ID.

10

WORKGROUP

TL_EMPL_DATA

Workgroup ID.

11

PAYGROUP

JOB

Paygroup.

12

EMPL_STATUS

JOB

Employee status.

13

REG_TEMP

JOB

Regular or temporary indicator.

14

FULL_PART_TIME

JOB

Full-time or part-time indicator.

15

EMPL_TYPE

JOB

Employee type indicator (hourly, salaried, and so on).

16

PER_TYPE

PERSONAL_DATA

Personnel type indicator.

17

COMPANY

JOB

Company.

18

JOBCODE

JOB

Job code.

19

LOCATION

JOB

Location.

20

COMPRATE

JOB

Compensation rate.

21

UNION_CD

JOB

Union code.

22

DEPTID

JOB

Department ID.

23

BUSINESS_UNIT

JOB

Business unit.

24

POSITION_NBR

JOB

Position number.

Note: This table contains data on the employees in each batch of time reporters for the period of interest defined by the Build Rule Map process. Because it only contains data for the period of interest defined by the rule map process, you cannot use it as a source of human resources data for periods extending beyond the period of interest.

Prioritizing Rules in Rule Programs

Consider rule priority when dependencies exist among the rules in a rule program. For example, you've defined these rules for the organization:

  • Default TRC: Set any blank TRC to REG.

  • Daily 8: Pay overtime (OT1.5) for hours worked in excess of 8.0 per day.

  • Daily 12: Pay double time (OT2.0) for hours in excess of 12 per day.

  • Weekly 40: Pay overtime (OT1.5) for hours worked in excess of 40 per week.

In this example, the second, third, and fourth rules evaluate time with a TRC of REG. In addition, they are replace-type rules, for which REG is reduced to the threshold number and a new TRC is created for the excess hours. Based on this information, order your rule program as follows:

  1. Default TRC

    Other rules must evaluate TRC REG.

  2. Daily 12

    This must execute before the Daily 8 rule because REG is set to 12 if hours are over 12. If the Daily 8 rule runs first, the Daily 12 rule does not generate double time because all records with hours over 12 are set to 8.

  3. Daily 8

    Daily 12 reduces hours in excess of 12 to 12.

  4. Weekly 40

    Executed last because it needs to capture all the REG hours (including REG hours that are reduced by daily rules and REG hours that are not altered by daily rules).

Time Period Selection for A Rule

When creating rules, carefully analyze the time period to use. For rules that apply to punch time reporters, evaluate your daybreaker and the relationship between the out punch of one day and the in punch of the next day. In many cases, you may need to apply a time period greater than a day for the proper evaluation of a daily rule.

Rules Testing

Always test any rule you create using an interactive SQL tool. Otherwise, the system could generate incorrect results when it processes the rules.

Note: When testing a template-built rule, you may need to replace meta-SQL with platform specific code and enter values for variables that users would normally insert into the template's condition and action statements through the template pages.