Calc Codes
Overview
Calculation Formulas (Calc Codes) are used in the Payroll system to allow flexibility and customization in CDH Calculations.
CDH Calculations
Processing Contributions, Deductions, and Hours within Payroll (i.e., Force Calc/PY200) may involve the use of Calculation Formulas. Each formula needs to be expressed in the correct syntax and may involve several different key words. The calculations are processed by manipulating various values. To effect change in the database clusters, attributes must be set to the desired amounts (either dollars or numbers of hours).
When writing calculations formulas, numbers must have a digit preceding the decimal point (i.e., ".01" is NOT a valid number, "0.01" is a valid number).
The only clusters that may be modified during the calculation process are those whose name ends in an "X" (e.g., DEDX - Deductions), except HBSX and PBSX. After processing each calculation, the system writes an entry to the Employee's Paid History record based on the "X" entries (e.g., DEDX.AMT would be written to history as the amount of the deduction whose calculation was just processed). Many of the other types of clusters may be accessed for read-only purposes during the calculation process. Each of the clusters which may be modified when processing CDHs are listed below:
CNTX This cluster contains Contribution-related information used in the calculation.
DEDX This cluster contains Deduction-related information used in the calculation.
HBSX This cluster contains Hour Base-related information used in the calculation.
HRSX This cluster contains Hour-related information used in the calculation.
HSTX This cluster is used to read history entries while processing a calculation formula
MSCX This cluster contains miscellaneous values used in calculations.
PBSX This cluster contains Pay-Base-related information used in the calculation.
PYPX This cluster contains Pay-Assignment-related information used in the calculation.
Referenced Values
All calculations are done by manipulating a combination of clusters/attributes, constants, and variables.
Clusters and Attributes
Clusters and Attributes are used by the system to uniquely identify specific data elements within various BusinessPlus modules. To obtain a full listing of the clusters and attributes available in each system, key in PYREFLAT. For a listing of clusters and attributes, including those that can be used in Payroll calc codes, refer to PYUPCL documentation.
Constants
Both numeric and alphanumeric constants are supported. Numeric constants may be expressed as any number from -99999999.99999 through 999999999.99999. Alphanumeric values may consist of up to 20 characters enclosed in double quotes.
Example:
NVAR0 := 999999999.99999
or
CVAR0 := "BusinessPlus Payroll system!"
Variables
Both numeric and alphanumeric variables are supported. Twenty system-defined names for these variables are available. Numeric variable names are in the form "NVAR#" where, # is a number ranging from 0 - 9. Alphanumeric variable names are in the form of "CVAR#" where # is a number ranging from 0 - 9.
NVAR0 ;through NVAR9
Values kept in these variables are in S9(9)V9(5) format. Numeric values stored in alphanumeric fields may be referenced as long as the values consist of only numbers.
Example:
NVAR0 := 999999999.99999
or
NVAR0 := CVAR0
CVAR0 ;through CVAR9
Values kept in these variables may be up to 20 characters. Values stored in numeric fields may be referenced.
Example:
CVAR0 := "BusinessPlus Payroll system!"
or
CVAR0 := NVAR0
Recognized Symbols
The following lists all symbols recognized by the calculation formulas including rules on their use and examples.
Arithmetic +, -, *, /
Addition ( + ), subtraction ( - ), multiplication ( * ), and division ( / ) may all be used to calculate various values.
Example:NVAR0 := (NVAR0 - 5) *** CNTD.VAL {NVAR1}
Assignment :=
To assign a value to a variable or cluster and attribute, use this symbol.
Example:NVAR0 := EDED.CD {1}
Braces { and }
These are used when referencing subscripts or multiple occurrences.
Example:NVAR0 := (NVAR0 - 5) * CNTD.VAL {NVAR1}
Brackets [ and ]
These are used when extracting or assigning parts of a character variable.
Example:CVAR0 [5,2] := "PY"
where, the first numeric (5) refers to the start position and the second numeric (2) refers to the length. Thus, if CVAR0 was XXXXXXXX, it would now be XXXXPYXX.
Note: The calc code compile has a known quirk which precludes a STOP command from being followed by a line which contains Braces. For example, the following syntax would not pass through the compiler successfully:
10 STOP
20 NVAR0 := EMPM.VAL {1}
Any executable command inserted between these two will remedy the problem. For example:
10 STOP
20 LABLE0
30 NVAR0 := EMPM.VAL {1}
Documentation << and >>
These are used to document or denote comments within a formula. Alphanumeric characters enclosed in these symbols will be ignored by the calculation process. A GOTO key word may not be directed to a statement containing these symbols.
Example:<<This calculation does the following 10 things: >>
Operand Separator
A comma (,) is used to separate various operands within an expression.
Example:CVAR0 [5,2] := "PY"
Parentheses ( and )
These are used to group operands and to parenthesize arithmetic and relational statements.
Example:NVAR0 := (NVAR0 - 5) * CNTD.VAL {NVAR1}
Relational <, >, =, <>, <=, and >=
Less than (<), greater than (>), equal to (=), not equal to (<>), less than or equal to (<=), and greater than or equal to (>=) may be used to determine the relationships among various data elements.
Example:DO
NVAR0 := NVAR0 + 1
UNTIL NVAR0 > 10
Valid Key Words
The following is an alphabetical list of valid key words, the rules associated with their use, and examples of their syntax.
AND and OR
"And" and "Or" may be used to perform logical tests that determine if specified conditions are met.
Example:IF (EMPM.HDT > "19910101" AND CVAR0 = "M") OR CVAR0 = "X"
NVAR0 := NVAR0 + 1
ENDIF
COPY
Copy may be used to duplicate an entire calculation formula from a specified CDH to the one that is currently being defined.
Example:COPY 1001
DEBUG
The DEBUG key word may be used to have information useful in testing calculation formulas print out automatically, when the formula is processed. Two operands are required to specify which employee's information and at what level of complexity the information will be printed on the WARN200 report.
Example: DEBUG ("000002",1) - To print Employee ID 000002 information.
or
DEBUG (" ",1) - To print all employee information.
DEFINE
The DEFINE key word initializes a cluster based on another cluster's definitions. After further manipulation, the newly defined cluster is used to update the database. Both, the cluster being initialized and the cluster the initialization is to be based on, must be specified with periods following their names. The cluster names of NEW and OLD are reserved for defining new and old buffers.
Example:DEFINE TEMP.ADDR.
DISPLAY
The DISPLAY key word is used to have a message (of up to 20 characters in length) printed to the screen (STDLIST) when the calculation is processed. This key word accepts a number of operands including alphanumeric values enclosed in quotes (e.g., "Error"), cluster and attribute values (e.g., EMP.ID), and variables (e.g., NVAR0). The first operand must be an alphanumeric value and operands must be separated by commas (,).
Example:DISPLAY ("Error ", EMPM.ID, "in inactive")
DISPLAY ("NVAR0 currently = ", NVAR0)
DO and UNTIL
The DO and UNTIL key words may be used to cause processing to be repeated until the specified conditions are met. The DO must be matched with an UNTIL. This statement can be nested.
Example:DO
NVAR0 := NVAR0 + 1
UNTIL NVAR0 > 10
GOTO and LABEL
The GOTO and LABEL key words may be used to branch processing to another area of the for GOTO must be followed by a statement sequence number or the LABEL# key word. The execution of the calculation is transferred to the statement with the designated sequence or label number once the GOTO command is encountered. A GOTO will not process correctly if the line that the GOTO directs processing to does not contain a key word.
Example: Both of the following statements would go to the same place. The main advantage of using the LABEL key word is that if line 998 ever gets renumbered, the calculation formula would not need to be modified.
100IF EMPM.TYPE = "PT"100IF EMPM.TYPE = "PT"
200 GOTO 998200 GOTO LABEL1
300ENDIF 300ENDIF
......
998NVAR1 := 1000998LABEL1
... 999NVAR1 := 1000
IF, ELSE, and ENDIF
The IF, ELSE, and ENDIF key words are used when conditions need to be tested. Each IF must be matched by an ENDIF. This statement can be nested.
Example:IF NVAR0> 254
NVAR0 := NVAR1
ELSE
NVAR0 := NVAR2
ENDIF
LOAD
This key word loads the value of an attribute from an HRIS cluster or an entire cluster from a Payroll/Position Control cluster. Two operands must be used when specifying the LOAD key word. This first operand must be the name of the cluster and attribute to be loaded and the second operator identifies which entry in that CLST.ATTRIB to load. To load an entire Payroll cluster, specify the attribute that is identified as the "key" attribute for the desired cluster.
Example:LOAD (EMPM.ID,"000002")
The employee master record with an ID of "000002" will be loaded.
PUT, DELETE, and UPDATE
These key words are used for updating a database. One operand is required which consists of the cluster name, followed by a period, and enclosed in parentheses.
Example:PUT (EDED.)
DELETE (EDED.)
UPDATE (EDED.)
ROUND0 through ROUND5
This key word rounds to the nearest value of the operand given the number of decimal digits indicated by the command itself. The operand must be enclosed in parentheses.
Examples:NVAR1 := 1.2367
ROUND2 (NVAR 1)
Result is NVAR1 equals 1.24
NVAR2 := 1.235
ROUND2 (NVAR2)
Result is NVAR2 equals 1.24
NVAR3 := 1.2345
ROUND2 (NVAR3)
Result is NVAR3 equals 1.23
STOP
The STOP key word causes the execution of the calculation to be terminated. Execution is also terminated when the commands encompassed in the formula are completed.
Example:IF MSCX.STATUS = "FAILED"
WARN("This process failed")
STOP
ENDIF
TRUNC0 through TRUNC5
This key word truncates the value of the operand to the number of decimal digits indicated by the command itself. The operand must be enclosed in a pair of parentheses.
Examples:NVAR1 := 1.2367
TRUNC2 (NVAR 1)
Result is NVAR1 equals 1.23
NVAR2 := 1.235
TRUNC2 (NVAR2)
Result is NVAR2 equals 1.23
WARN
The WARN key word is used to have a message (of up to 20 characters in length) printed on the WARN200 report when the calculation is processed. This key word accepts a number of operands including alphanumeric values enclosed in quotes (e.g., "Error"), cluster and attribute values (e.g., EMPM.ID), and variable values (e.g., NVAR0). The first operand must be an alphanumeric value and the operands are separated by commas (,).
Example:WARN("Inactive employee :", EMPM.ID)
or
WARN("Current value of NVAR0=", NVAR0)
Editing Commands
The following commands may be used in the Edit field on the CDH Definition pages (PYUPCC, PYUPDD, or PYUPHH) to facilitate editing and creating calculation formulas.
COPY xyyy or C xyyy
where x indicates whether to copy from the contribution, deduction, or hour number that follows (x=1 for contributions; x=2 for deductions; x=3 for hours); yyy is the number of the CDH from which to copy the calculation formula into the CDH being defined (replacing the current calculation formula, if any). For example, entering "COPY 2312" directs the system to copy the calculation formula from deduction number 312 into the CDH currently being defined (replacing the current calculation formula, if any).
DELETE x
DELETE y-z
where x indicates the line number to be deleted; y and z indicate the low and high ends of a range of line numbers to delete, respectively. For example, "DELETE 35" directs the system to delete line 35; "DELETE 55-105" directs the system to delete lines 55 through 105 inclusive.
GOTOLABELx
where x is a numeric value. Place the LABEL where the calc code should jump to.
INSERT x B y or I x B y
where x indicates the number of lines to be inserted before line number y. For example, "INSERT 4 B 10" directs the system to insert 4 lines before line number 10.
INSERT x A y or I x A y
where x indicates the number of lines to be inserted after line number y. For example, "INSERT 4 A 10" directs the system to insert 4 lines after line number 10.
RENUMBER x or R x
where x indicates the number of lines by which to renumber the calculation formula. For example, "RENUMBER 10" directs the system to renumber the calculation formula by tens.
LOAD CDHxyyy or L CDHxyyy
where x indicates whether to load from a flat file named CDHxyyy into the contribution, deduction, or hour number that follows (x=1 for contributions; x=2 for deductions; x=3 for hours); yyy is the number of the CDH into which the calculation formula is to be loaded. For example, enter "LOAD CDH2312" directs the system to load the calculation formula stored in a file named CDH2312 (located in the user's group) into deduction number 312.
SAVE CDHxyyy or S CDHxyyy
where x indicates whether to save the contribution, deduction, or hour number that follows (x=1 for contributions; x=2 for deductions; x=3 for hours); yyy is the number of the CDH from which the calculation formula is to be saved into a flat file. For example, entering "SAVE CDH2312" directs the system to save the calculation formula for deduction number 312 in a flat file named CDH2312. The file name selected may not exist in the user's group prior to issuing the command.