AdvPl Payroll Calculation Scripts Guide
AdvPl Payroll Calculation Scripts Guide
Basic Concepts:
Created :
May 16, 2008
Creation of Calculation Scripts for the Payroll
Payment (SIGAGPE) Updated:
May 16, 2008
Memory Variables
Data Types
Numeric
AdvPl does not differentiate between integer values and floating-point values, so one can create
variables
numerical with any value within the allowed range. The following elements are of the type of
numerical data:
2 43.53
0.5
0.00001
1,000,000
A numeric data type variable can contain an eighteen-digit number including the decimal point.
floating, in the range of 2.2250738585072014 E–308 to 1.7976931348623158 E+308.
Logical
Logical values in AdvPl are identified by .T. or .Y. for true and .F. or .N. for false.
(regardless of whether the characters are in uppercase or lowercase).
Character
Strings or character strings are identified in AdvPl by blocks of text between double quotes.
" or single quotes ('):
Hello world!
This is a string
This is 'another' string
A character type variable can contain strings with a maximum of 1 Mb, that is, 1048576.
characters.
Data
AdvPl has a specific data type for dates. Internally, the variables of this data type
are
stored as a number corresponding to the Julian date.
Data type variables cannot be declared directly, but rather through the use of
of
specific functions such as ctod that converts a string to date.
Matrix (Array)
Matrices are a special type of data. It is the arrangement of other elements in columns and rows. The
AdvPl
supports one- or multidimensional arrays. The elements of an array are accessed through
indices
numerical starting from 1, identifying the row and column for as many dimensions as exist.
A matrix can contain a maximum of 100,000 elements, regardless of the number of
dimensions.
Matrices should be used with caution, as if they are too large they may exhaust memory.
server.
Created :
May 16, 2008
Creation of Calculation Scripts for the Payroll
Payment (SIGAGPE) Updated:
May 16, 2008
Code Block
The code block is a special type of data. It is used to store instructions written in
AdvPl
that can be executed later.
Memory variables are one of the most important resources of a language. They are areas of
memory
created to store information used by a program to perform tasks. By
example, when the user types in any information, such as the name of a product, in a
the screen of a program this information is stored in a memory variable for
subsequently to be recorded or printed.
From the moment a variable is created, it is no longer necessary to refer to its
content, but rather to your name. The name of a variable is a unique identifier that follows two
rules rules:
Maximum of 10 characters. AdvPl does not prevent the creation of a memory variable whose name
contain more than 10 characters, but only the first 10 will be considered for the
location of the stored content. Therefore, if two variables are created whose first 10
characters were
equal, such as nTotalGeralAnual and nTotalGeralMensal, references to any of them in the program
they will result in the same. That is, they will be the same variable:
nTotalGeralMensal := 100
nTotalGeralAnual := 300
Alert("Monthly value: " + cValToChar(nTotalGeralMensal))
When the content of the variable nTotalGeralMensal is displayed, its value will be 300. This happens
because at the moment this value was assigned to the variable nTotalGeralAnual, AdvPl considered
just
the first 10 characters (just as it does when it needs to display the value of the variable
TotalGeneralMonthly
that is, considered them as the same variable. Thus the original value of 100 was replaced by the one of
300.
Character limit on the name. Variable names must always start with a letter.
or the
underscore character ( _ ). In the rest, it can contain letters, numbers, and the underscore character.
Any other characters, including whitespace, are not allowed.
AdvPl allows for the unlimited creation of variables, depending only on the available memory.
to follow
here are some valid names for variables:
TOT01
cNumber
ANY_VAR
M_CARGO
A11
AdvPl is not a strongly typed language for variables, meaning it is not necessary to specify the
type of data that a certain variable will contain at the time of its declaration, and its value can
change during the execution of the program. There is also no need to declare variables in a
specific section of your source code, although it is advisable to declare all variables
necessary at the beginning, making maintenance easier and avoiding variable declaration
unnecessary.
To declare a variable, one must use a scope identifier, followed by a list of
variables
separated by commas (,). A scope identifier is a keyword that indicates the context to which
of the program the declared variable belongs. The context of variables can be local (viewed
only within the current program), public (viewed by any other program), among others.
The
Different types of variable context are explained in the documentation on variable scope.
Consider the example lines of code:
If this line is executed in an AdvPl program, a runtime error will occur with the message
variable does not exist: nPercentual, as this variable is being used in an expression of
calculation without having been declared. To solve this error, the variable must be declared beforehand:
In this example, the variables are declared beforehand using the local scope identifier.
When the calculation line is executed, the non-existent variable error will no longer occur. However
Uninitialized variables always have the default value of null (Nil) and this value cannot be used.
in a calculation as it will also generate execution errors (null cannot be divided by 100). A
The resolution of this problem is performed by initializing the variable in one of the ways:
The difference between the last example and the two previous ones is that the variable is initialized at the moment of
declaration. In the first two examples, the variable is first declared and then initialized in a
another line of code. The store command exists only for compatibility with earlier versions and
other languages xBase, but it is obsolete. The assignment operator (:= or just
=). É
it is advisable to choose the compound assignment operator of colon and equal sign, because the
assignment operator using only the equals sign can easily be confused with the
relational operator (for comparison) during the creation of the program.
Once a value is assigned to you, the data type of a variable is equal to the data type of the
assigned value. That is, a variable becomes numeric if a number is assigned to it, it becomes
if a string of text is assigned to it, etc. However, even if a variable is of
a certain type of data, one can change the type of the variable by assigning another type to it:
07 Alert(cValToChar(xVariable))
08
09 xVariable := .T. // Now the variable is logical
10 If xVariable
11 Alert("The variable has a true value...")
12 Else
13 Alert("The variable has a false value...")
14 Endif
15
16 xVariable := Date() // Now the variable is date
17 Alert("Today is: " + DtoC(xVariable))
18
19 xVariable := nil // Null again
20 Alert("Null value: " + xVariavel)
21
22 Return
In the previous example program, the variable xVariavel is used to store various types of
The lowercase letter 'x' at the beginning of the name is used to indicate a variable that can
contains various types of data, according to Hungarian Notation (refer to specific documentation for
details).
This program swaps the values of the variable and displays its content to the user through the function.
alert.
This function receives a parameter that must be of the character string type, so depending on the
the data type of the variable xVariavel requires a conversion beforehand.
Despite this flexibility in the use of variables, care must be taken when passing
parameters for functions or commands, and in the concatenation (or addition) of values. Note line 20 of
example program. When this line is executed, the variable xVariable contains the null value. The
attempting to sum different data types results in a runtime error of the program. On this line of
for example, an error will occur with the message 'type mismatch on +'. Except for the case of the value
null, for the others you should always use conversion functions when you need to concatenate
different data types (for example, in lines 07 and 17.
Note also that when a variable is of the logical data type, it can be used directly.
for checking (line 10):
If xVariable
it is the same as
If xVariable = .T.
The declaration of variables for other data types, arrays, and code blocks is exactly
the same as described so far. There are just some differences regarding initialization, which may
to be
consulted in the documentation of matrix initialization and code blocks.
Common Operators
In the documentation about variables, there is a brief demonstration of how to assign values to a
variable in the simplest form. AdvPl significantly expands the use of variables through
of use of
expressions and functions. An expression is a set of operators and operands whose result can
can be assigned to a variable or analyzed for decision-making. For example:
In this example, some expressions are used to calculate the net salary after a raise.
The
Created :
May 16, 2008
Creation of Calculation Scripts for Payroll
Payment (SIGAGPE) Updated:
16/05/2008
Mathematical Operators
Addition
Subtraction
Multiplication
/ Division
** or ^ Exponentiation
% Modulo (Remainder of Division)
String Operators
Relational Operators
The operators used in AdvPl for relational operations and evaluations are:
Lesser Comparison
Greater Comparison
Equal Comparison
== Exact Match (for characters)
Less Than or Equal
>= Greater Than or Equal To
<>
you
#
or
!=
Logical Operators
The operators used in AdvPl for logical operations and evaluations are:
Assignment Operators
The operators used in AdvPl for assigning values to memory variables are:
Simple Assignment
Line Assignment
+= Addition and Assignment in Line
Subtraction and Assignment in Line
*= Multiplication and Assignment in Line
Division and Assignment in Line
= or ^= Exponentiation and Inline Assignment
%= Modulo (remainder of division) and Inline Assignment
Simple Assignment
Created :
May 16, 2008
Creation of Calculation Scripts for the Payroll
Payment (SIGAGPE) Updated:
May 16, 2008
Inline Assignment
The inline assignment operator is characterized by a colon and the equal sign. It has the
same function as the equal sign alone, but it expands the assignment to the variables. With it one can
assign multiple variables at the same time.
When multiple variables are initialized in the same line, the assignment starts from the right.
for the
left, that is, nVar3 initially receives the value zero, nVar2 receives the content of nVar3 and nVar1
receives the content of nVar2 finally.
With the inline assignment operator, individual initializations of each can be replaced
variable
for a single initialization:
Composite Attribution
The compound assignment operators are a feature of the AdvPl language for expressions of
calculation and assignment. With them, you can save typing:
-= X -= Y X = X - Y
*= X *= Y X = X * Y
/= X /= Y X = X / Y
**= or ^= X **= Y X = X ** Y
%= X %= Y X = X % Y
Increment/Decrement Operators
The AdvPl language has operators to perform increment or decrement of variables. It understands-
himself
by incrementing, increase the value of a numeric variable by 1 and it is understood by decrementing
decrease the value of the variable by 1. The operators are:
The decrement/increment operators can be placed both before (prefix) and after
(post-fixed) of the variable name. Within an expression, the order of the operator is very
important
potentially changing the result of the expression. Incremental operators are executed from the left
to the right within an expression.
Local nA := 10
Local nB := nA++ + nA
Created :
May 16, 2008
Creation of Calculation Scripts for the Payroll
Payment (SIGAGPE) Updated:
May 16, 2008
The value of the variable nB results in 21, since the first reference to nA (before the ++) contained the value
10
which was considered and immediately increased by 1. In the second reference to nA, it already had the
value 11. What was done was the sum of 10 plus 11, equal to 21. The final result after execution
of these two lines is the variable nB containing 21 and the variable nA containing 11.
I don't understand.
Local nA := 10
Local nB := ++nA + nA
It results in 22, as the incremental operator increased the value of the first nA before its value.
ditch
considered.
Special Operators
In addition to the common operators, AdvPl has some other operators or identifiers. These are
yours
purposes:
Grouping or Function
Matrix Element
Definition of Matrix, Constant or Code Block
Nickname Identifier
& Macrosubstitution
Parameter passing by reference
Converters
NTotal := 10
Alert(cValtochar(ntotal))
10
ntotal := 500 + val(cvalor)
Created :
May 16, 2008
Creation of Calculation Scripts for the Payroll
Payment (SIGAGPE) Updated:
May 16, 2008
123
strzero(val(cmatant),6)
Result := 000123
01/31/2008
Date of admission
Canomes := month(sra->admission_date)
1200.32
Nsubtot := int(ntotal)
Resultado = 1200
nmes := month(sra->ra_admissa)
nmes := year(sra->ra_admissa)
Jorge Paiva
Csobnome := subs(cnome, 6, 5)
Size := LEN(cname)
Resultado = 11
cnome := Trim(cnome)
Created :
May 16, 2008
Creation of Calculation Scripts for the Payroll
Payment (SIGAGPE) Updated:
May 16, 2008
JorgePaiva
jorge@paiva
Cnome := strtran(cnome,"@",".")
Result: [Link]
Position and bring the value of a field from another table: POSITION
Example:
Example
Created :
May 16, 2008
Creation of Calculation Scripts for the Payroll
Payment (SIGAGPE) Updated:
May 16, 2008
Note on the screen above the order to put in the 2nd parameter 'Index' the reason we filled it with '1'.
Because the search key is in order one, if we wanted the CBO it would be order two.
fBuscaPD
Objective: Returns the sum of the Values or Quantities of the indicated Funds.
cType = Type of summation to be performed. It can be "H" for the summation to be made.
Amounts of the funds or "V" so that the amounts of the funds are summed. If not
the indicated will be assumed as 'V'.
"V" or "H"
Usage Example:
It will store in the variable 'nHorExt' the sum of the QUANTITIES OF HOURS OF
VERBAS105, 106, 107, 108, 109 and 110 from week 40.
nValExt := fSearchPD("105,106,107,108,109,110")
It will store in the variable 'nValExt' the sum of the VALUES of items 105, 106, 107.
108, 109 and 110.
Note: When summing discount amounts, the system returns this value.
NEGATIVE. It must be multiplied by (-1) when the amount to be generated depends
of this result.
Usage Examples:
Generate the budget 460, with 10% on the value of the discount budget 452.
nValExemp := fBuscaPD("105,106,110,410,405")
Created :
May 16, 2008
Creation of Calculation Scripts for the Payroll
Payment (SIGAGPE) Updated:
May 16, 2008
It will store in the variable 'nValExemp' the sum of the VALUES of the accounts 105, 106, and 110
Less the amounts of items 410 and 405.
FbuscaACM
Accumulated amount
105
Men/Hour = Condition to restrict the search. It can be 'H' for it to be done for the
hourly category or 'M' for the monthly category or by a specific union,
etc.
"H" or "M"
Inform the start date (DDMMYYYY) for searching within the Accumulated data
annual.
End date (DDMMAAAAA) to inform for the search within the Accumulated
annual.
Return value.
Quantity of return.
fGeraVerba
Syntax:fGeraVerba(cCode,nValue,nHour,cWeek,cCostCenter,cType1,cType2,nInstallments, dDate,lChange)
Type of the Amount. It can be 'V' for Value, 'H' for Hours, or 'D' for Days. If
if not informed, it will be assumed "V".
cTipo2= After the Type, Type 2 must be informed. 'I' can be informed for
"A" for Advance, "C" for calculated, "K" for Vacation.
Null= After the installment, a Null parameter must be specified, meaning it must be placed
TWO commas after the Installment.
Created :
May 16, 2008
Creation of Calculation Scripts for the Payroll
Payment (SIGAGPE) Updated:
16/05/2008
dData = Date of the actual payment of the funds. The variable can be used
"dData_Pgto" which is the date provided in the calculation questions.
lAltera = Logical variable to indicate if the budget can be changed, if it already exists in
employee movement. It can be .T. or .F..
Example of Use:
Note: If the user only needs the last argument, lAltera, they may leave the others in
white, so that the System takes the default.
Example:
The system will reallocate the budget 222, with the value of the variable ValExtra and the quantity of hours.
varExtHours
If you do not want the hours field to be overwritten, the function will be:
Note: If the argument ".T." is omitted, the system will not overwrite the entry if it already exists.
assuming, therefore, the argument ".F." as default.
The function fgeraverba does not re-record funds informed by the user, therefore for cases that
if necessary, the following procedure should be followed in the calculation script:
Condition
If FlocaliaPd("999") > 0 Locate the position of the fund '999' in the Array aPd
True
aPd[fLocaliaPd("999"),5] := ((MonthlySalary * 0.10) * FindPd("999", "H"))
Example. Record the following calculation in the Value Position on the aPD:
((Salary * 10%) * Reported Hours)
Matrix aPd
Matrix where the Funds Are Calculated and Created through Calculations
Example of Use:
aPD[fLocaliaPD("113"),9]:="D"
FdelPd
Usage Example:
fDelPd("222,109,409")
fDelPd("222,109,409",cSemana)
Matrix aPdv
Functions:
nUltDia := f_UltDia(dData) Returns the last day of the month of the date
passed as parameter
SumInc Function
Objective: To sum the funds in the aPd matrix according to the requested incidences.
Syntax: SumInc(aPd,nElem,nBas,nCond1,cParc1,nCond2,cParc2,nMes,lSemana,aCodfol)
Total Income:
Total Discounts
0.00
aEval(aPD,{|X| SomaInc(X,1,@nTotDesc, , , , , , ,aCodFol})
Liquid
nInssBas:=0.00
aEval(aPD,{|X| SomaInc(X,4,@InssBas,12,"N", , , , ,aCodFol})
0.00
aEval(aPD,{|X| SomaInc(X,5,@IrBas,11,"N","12","N" , , ,aCodFol})
Gross Value
ValBruto:=0
Aeval(aPD,{|X|SomaInc(X,5,@ValBruto,11,"N",12,"N",, ,aCodFol)})
Perform the summation of the events that apply for withholding income tax (IRRF) and are marked as 'N' for the fields 'Refers to'
"The Vacation" and "Refers to the 13th", accumulating this value in the variable "ValBruto".
Note: Regarding the "Entry Point" of the Formulas, the user should study the moment of
calculation, providing the correct/appropriate sequence.
nPerc:=PosSrv("114",SRA->RA_BRANCH,"RV_PERCENT")
GETMV("MV_DIASMONTH")
Mnemonic
Mnemonics are variables used in writing a program. This registration will be stored
all the variables that will be available to be used in the preparation of Calculation Script,
Registration of Formulas and Function Library. For each mnemonic, there must be a definition of
type and an initialization:
Content - If it is content that will be calculated, inform 0 (zero); if it is fixed content, inform.
the value, example: 1200.00. Note: Observe that the value of the cents must be separated by a period and
not by comma.
[Link] Calç. : This field must be filled in Yes when the system performs the calculation and No
when the value is fixed.
Function Library
Functions are sequences of computer program instructions that perform a specific task.
procedure.
Your tasks can be modified and adapted to the user's needs through a number
of elements called parameters. Function parameters are information that defines the
limits or actions of a routine.
This routine allows the maintenance of the functions that will be used in the Personnel Management environment.
together with the functions available in the Protheus environment. The previously registered functions.
will facilitate the process of creating formulas.
In this registration, the number of parameters will be defined, the type of each one, and whether the
whether it should be mandatory or not.
Example:
The FPOSREG function verifies and positions in a file record based on the indicated key.
Function: FPOSREG('SRB',1,SRA->RA_BRANCH+SRA->RA_MAT,.F.)
Formulas
This registration allows for the maintenance of formulas that will be used in the Calculation Script.
A formula is a set of expressions that may contain functions, file fields, mnemonics,
constants and calls to other formulas.
This registration allows for the assembly of specific calculations to meet collective agreements and others.
particularities of the company or the category.
Normally every formula starts with a condition; the example below reports a condition of a
Field data in the employee registration comparing with the month and year of the payroll.
Sequence 0010
On the screen above, select the Type of Expression (3) Functions and double-click on the function.
ANOMES in the box (Functions).
The help screen for filling out functions will appear, as shown in the figure below:
Created :
May 16, 2008
Creation of Calculation Scripts for the Payroll
Payment (SIGAGPE) Updated:
May 16, 2008
Fill in the Par Content field with the date field in the employee registration that will be our
condition. After clicking OK
Note on the screen above that the function will appear in the field below (Selected Expression). You will be able to,
Since we are going to use the GETMV function, we have to choose type (3) Functions, that is, whenever
to use functions we must choose the type Functions, even if this function does not exist in the box of
functions. Then enter the expression in the 'Selected Expression' field. After click OK
On the screen above, we chose the .END option because we will not have another condition, if that were the case.
Sequence 0020
We will choose the option above because we want not another condition but an execution.
After clicking OK
Select the type (3) Functions and double click on the function Fgeraverba
Fill in the Parameter Budget with the budget that will be generated for the payroll. Don't forget.
It has to be in quotes and clicking on the magnifying glass won't help, that is, it has to be typed.
Fill in the Value parameter with the mathematical formula to be calculated
Created :
May 16, 2008
Creation of Calculation Scripts for the Payroll
Payment (SIGAGPE) Updated:
May 16, 2008
Fill in the HrsDias parameter if necessary with the reference that should appear on the sheet.
payment.
After clicking OK
Note on the screen above that the function will appear in the field below (Selected Expression). You will be able to,
On the screen above, we chose the option .END. because we will not have another execution, if that were the case.
1st File
On the screen above, choose the type (1) Files / Fields, then fill in the Search field with the table
desired, for example 'SRA', then double-click on the 'Fields' group, in the desired field. This
The option will serve for us to use a field from a registration in the formula.
2nd Mnemonics
Created :
May 16, 2008
Creation of Calculation Scripts for the Payroll
Payment (SIGAGPE) Updated:
16/05/2008
On the screen above, choose the type (2) Mnemonics, then double-click on the desired mnemonic.
the option will serve for us to use the mnemonics in a formula.
5th Constant
On the screen above, choose the type (5) Constant, then add the constant to the 'Selected' group.
Expression. This option will allow us to use any fixed value for the creation of a formula.
Remembering that if it is numeric, it does not need to be informed in quotes, only characters are informed in quotes.
2 – Create a formula to perform the calculation, we need to know the code of the fund that will be used to
payment of the bonus.
In the first execution, our variable (mnemonic) receives the value of the salary, at the end of the line.
we insert in the operator CNT for continuation on the next line.
In the second execution (another row), we used the FGERAVERBA function indicating the fund to be
used to pay the bonus and the amount to be paid (mnemonic) by receiving the own variable
that in the previous line received the salary multiplied by 10% of himself (salary).
Note: Try to insert into the script after a logical sequence of what is being calculated, in our
example does not exist in the script a sequence for calculating gratification therefore it was inserted in the
00321.
Exercise:
Tips:
CREATE Mnemonic: M_REST to store the value of rest
Create mnemonic: M_VERBREP to store the value of the HE +
commission
Use as a condition to have the shift '001'
Use the FbuscaPD function to sum the funds (HE + commission)
Use the function Fgeraverba
Note: Disable scripts 00210, 00590, 00600, and 00610 as they calculate the
automatic rest.
Created :
May 16, 2008
Creation of Calculation Scripts for the Payroll
Payment (SIGAGPE) Updated:
May 16, 2008
#include "[Link]"
/*-----------------------------------------------------------------------*
Program 07/08/08
*------------------------------------------------------------------------*
Pension (HCM) *
*-----------------------------------------------------------------------*/
User Function RCFOL082()
nSalComp := 0
nValPen := 0
If SRA->RA_XPERC > 0
nValPen := (SRA->RA_SALARY * .30)
End If
nSalComp := (((SRA->RA_SALARY + nValPen) / 30) * 2)
FGeraVerba("418", nSalComp, , , , , , , , .T.)
Return
#include "[Link]"
/*-----------------------------------------------------------------------*
RCFOL082 07/08/08
*------------------------------------------------------------------------*
Pension (HCM) *
*-----------------------------------------------------------------------*/
User Function RCFOL082()
nSalComp := 0
nValPen := 0
nPert := .30
Return