0% found this document useful (0 votes)
66 views31 pages

AdvPl Payroll Calculation Scripts Guide

The document describes the basic concepts of memory variables in AdvPL, including data types, creation, and assignment of variables. It is explained that variables can store numbers, logical values, characters, dates, arrays, or blocks of code, and there is no need to declare the type in AdvPL.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views31 pages

AdvPl Payroll Calculation Scripts Guide

The document describes the basic concepts of memory variables in AdvPL, including data types, creation, and assignment of variables. It is explained that variables can store numbers, logical values, characters, dates, arrays, or blocks of code, and there is no need to declare the type in AdvPL.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Created :

May 16, 2008


Creation of Calculation Scripts for the Payroll
Payment (SIGAGPE) Updated:
May 16, 2008

Basic Concepts:
Created :
May 16, 2008
Creation of Calculation Scripts for the Payroll
Payment (SIGAGPE) Updated:
May 16, 2008

Memory Variables

Data Types

AdvPl is not a strongly typed language, which means that variables of


memory
can hold different types of data during the execution of the program. Variables can also contain
objects, but the primary types of the language are:

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.

Creation and Assignment of Variables

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

And some invalid ones:

1CODE (Starts with a number)


M CARGO (contains a blank space)
LOCAL (reserved word of AdvPl)
Created :
16/05/2008
Creation of Calculation Scripts for the Payroll
Payment (SIGAGPE) Updated:
16/05/2008

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:

Result := 250 * (1 + (nPercentage / 100))

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:

Local nPercentage, nResult


Result := 250 * (1 + (nPercentage / 100))

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:

Local nPercentage, nResult


Store 10TonPercentage
Result := 250 * (1 + (nPercentage / 100))
or
Local
nPercentual := 10
nResult := 250 * (1 + (nPercentage / 100))
or
Local nPercentual := 10, nResultado
nResult := 250 * (1 + (nPercentage / 100))

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:

01 Local xVariable // Declares the variable initially with a null value


02
Now the variable is a character...
04 Alert("Value ofText: " + xVariable)
05
06 xVariable := 22 // Now the variable is numeric
Created :
16/05/2008
Creation of Calculation Scripts for the Payroll
Payment (SIGAGPE) Updated:
May 16, 2008

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:

Local nSalario := 1000, nDesconto := 0.10


Local Increase, Net Salary
nSalario * 1.20
NetSalary := Increase * (1-Discount)

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

operands of an expression can be a variable, a constant, a file field or a


function.

Mathematical Operators

The operators used in AdvPl for mathematical calculations are:

Addition
Subtraction
Multiplication
/ Division
** or ^ Exponentiation
% Modulo (Remainder of Division)

String Operators

The operators used in AdvPl for character handling are:

String concatenation (union)


Concatenation of strings with elimination of trailing whitespaces from intermediate strings
$ Substring Comparison (contained in)

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:

And. It's logical


.[Link] logical
.Not. out ! NOT logical

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

The equals sign is used to assign a value to a memory variable.


nVariable = 10

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.

nVar1 := nVar2 := nVar3 := 0

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:

Local nVar1 := 0, nVar2 := 0, nVar3 := 0


for
Local nVar1 := nVar2 := nVar3 := 0
The inline assignment operator can also be used to replace field values in
um
database.

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:

Operator Example Equivalent to

X plus equals Y X equals X plus Y

-= 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:

++ Post or Pre-fixed Increase


Post or Pre-fixed Decrement

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

Parentheses are used to group elements in an expression changing the order of


precedence of expression evaluation (according to mathematical rules for example). Also
are used to wrap the arguments of a function. See the documentation on precedence of
operators for more details.
Brackets are used to specify a specific element of a matrix. For example,
A[3,2]
refers to the element of matrix A in row 3, column 2.
The keys are used for the specification of literal matrices or code blocks. For example,
A:={10,20,30} creates a matrix called A with three elements.
The symbol -> identifies a field of a file distinguishing it from a variable. For example,
FUNC-
name refers to the file name field FUNC. Even if there is a variable called name,
it is the name field that will be accessed.
The symbol & identifies an expression evaluation through macro and is seen in detail in
documentation on macro substitution.

Converters

From Numeric to character: cValtochar


Example:

NTotal := 10
Alert(cValtochar(ntotal))

From character to numeric: val


Example:

10
ntotal := 500 + val(cvalor)
Created :
May 16, 2008
Creation of Calculation Scripts for the Payroll
Payment (SIGAGPE) Updated:
May 16, 2008

From character to numeric by adding zero to the left: strzero


Example:

123
strzero(val(cmatant),6)
Result := 000123

From character to date: ctod or stod


Example:

01/31/2008

Date for character: dtoc


Example:

Date of admission

From date to Month and Year: monthyear


Example:

Canomes := month(sra->admission_date)

Number to integer number: int


Example:

1200.32
Nsubtot := int(ntotal)

Resultado = 1200

From day to Month: month


Example:

nmes := month(sra->ra_admissa)

From date to Month: year


Example:

nmes := year(sra->ra_admissa)

Select part of a string: SUBSTRING or SUBS


Example:

Jorge Paiva

Csobnome := subs(cnome, 6, 5)

Returns the numerical size of a String: LEN


Example:

Size := LEN(cname)

Resultado = 11

Return the same string without spaces: Alltrim


Example:

cnome := Trim(cnome)
Created :
May 16, 2008
Creation of Calculation Scripts for the Payroll
Payment (SIGAGPE) Updated:
May 16, 2008

JorgePaiva

Alters a character within a string: STRTRAN


Example:

jorge@paiva
Cnome := strtran(cnome,"@",".")

Result: [Link]

Position and bring the value of a field from another table: POSITION
Example:

Position('SRJ', 1, XFILIAL('SRJ') + SRA->RA_CODFUNC, 'RJ_DESCRIPTION')

Order Parameter Description Observation


1st Table Inform which table it will be in.
a search yes information
desired
2nd Index Inform which is the index order To understand, enter the registration of this table
the search key that will be and see in the search field of the browser the
used. Every table has a desired search key according to the figure.
or more indices and this are below.
in a sequential order
3rd Research Inform the content to be We must be careful when filling in the
searched so that we can find a branch, in the system's standard
the correct record. the table has the branch field, but not all
tables have this field filled in. If the
field not filled in with for example
the function registration fill in xfilial("SRJ") and
the system will fill in the branch of SRJ, or
be, none, however if you are going to research in
a table that has branch filled
fill in the survey, for example as SRA-
RA_BRANCH+SRA->RA_FUNC_CODE.
4th Return Report the field that will bring the
return requested. Always
in quotes.

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.

FUNCTIONS FOR USE IN FORMULAS

fBuscaPD

Objective: Returns the sum of the Values or Quantities of the indicated Funds.

Syntax: fSearchPD(cCodes, cType, cWeek)

Codes = List containing the code(s) of the item(s) to be added.


105,106,107 or 105

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"

Week Number, if not indicated assumes empty. It should only


to be used for employees whose payment frequency is 'weekly'.
14

Usage Example:

nHorExt := fBuscaPD("105,106,107,108,109,110", "H", "40")

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:

fGeraVerba("460", fBuscaPD("452") * (-1) * 0.1, , , , , , , , ,.T.)

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

Objective: Returns the value contained in the annual accumulations.

Syntax: fSearchACM(word, Message/Hour, startDate, endDate, type, ValueReturn, QuantityReturn)

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.

cType= Enter 'V' for value or 'H' for hours.

Return value.

Quantity of return.

fGeraVerba

Objective: Include or Change an Item in the Movement.

Syntax:fGeraVerba(cCode,nValue,nHour,cWeek,cCostCenter,cType1,cType2,nInstallments, dDate,lChange)

Code = Code of the Item to be generated.

nVal= Value of the Grant.

Amount of the Grant.

cSem = Week Number, should only be used for employees whose


payment frequency is weekly. The variable 'cSemana' can be used which
it is the week indicated in the program questions.

cCCusto= Cost Center Code of the employee.

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.

Number of Installments of the Grant. Must be between 0 and 99.

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:

fGeraVerba("222", nValExt, nHorExt, cSemana, SRA->RA_CC, "V", "I", 0, , dData_Pgto, .T.)

fGeraVerba("223", 0, SRA->RA_HRSMES, " ", SRA->RA_CC, "H","I" , 99, , dData_Pgto, .T.)

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:

fGeraVerba("222", nValExtra, nHorExt, , , , , , , ,.T.)

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:

fGeraVerba("222", nValExtra, , , , , , , , ,.T.)

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.

REWRITE THE AMOUNT INFORMED BY THE USER

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

Code of the Item


Week of the Verba
[Link] of the Grant
Hours
Value
Type 1 ([H]ours,[V]alue,[D]ays)
Type 2 ([I]nformed [C]alculate sheet [R]Calculate Resc. [F]Calculate Vacations [S]2nd Installment 1o.
Park
Share of the Amount
Type of the Expenditure in the Matrix ([D] = Deleted in the Matrix)
Release Date
Created :
May 16, 2008
Creation of Calculation Scripts for the Payroll
Payment (SIGAGPE) Updated:
16/05/2008

Example of Use:

aPD[fLocaliaPD("113"),9]:="D"

Delete item 113 from the monthly movement file.

FdelPd

Objective: Exclude/Delete Items in the Movement during the calculation.

Syntax: fDelPd(cCodes, cWeek)

Codes = Codes of the items to be excluded.


Sem. Week Number, must only be used for employees whose
the payment frequency is weekly. The variable "cSemana" can be used, which is the week
indicated in the program questions.

Usage Example:

fDelPd("222,109,409")

fDelPd("222,109,409",cSemana)

Matrix aPdv

Incidences of the amounts loaded through the fMatriz function.

Code of the Item


Percentage of the Amount
Corresponding Code
Incidence for INSS Base
Incidence for Income Tax Base
Incidence for FGTS Base
Incidence for Med. 13th
Incidence for Vacation Pay
Incidence for Hazard Pay Base
Incidence of Insalubrity Base
Refers to vacations
It refers to 13th
Incidence for Cost Map
Incidence for Rais
Incidence for Dirf
Incidence for Dsr without Hours
If it is Extra Hour Pay
If the Verba Incorporates Salary
If the Verba is for an additional time of service
Incidence for Union Contribution Base
Incidence for Family Salary Base
Incidence for Life Insurance Base
Incident for Average Notice Period
Incidence for Collective Bargaining Base
If the Amount is Deducted in the INSS Guide (GRPS)
If the Adjustable Average
If there is a formula for the allowance
Incidence for Alimony
Created :
16/05/2008
Creation of Calculation Scripts for the Payroll
Payment (SIGAGPE) Updated:
May 16, 2008

Functions:

nUltDia := f_UltDia(dData) Returns the last day of the month of the date
passed as parameter

nPosPd := fLocaliaPd("999") // Position of the Item in the Matrix aPd

Matrix aPd = Description for calculation script.

Code of the Item


Week of the Budget
[Link] of the Grant
Hours
Value
aPd[nposPd,6] = Type 1 ([H]ours,[V]alue,[D]ays)
aPd[nPosPd,7] = Type 2 ([I]nformed - [C]alculate sheet - [R]Calculate dismissal - [K]Calculate vacation
Park 2.0 - Park 1.0
Parcel of the Fund ¦
aPd[nposPd,9] = Type of the Item in the Matrix ([D] = Deleted in the Matrix) ¦
Payment Date ¦
¦

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)

aPD Matrix with the funds for Summation


nElem Incidence to be added according to the position in the aPdV matrix
nBas Return variable of the summation
nCond1 Element for 1st condition, according to position in the matrix aPdV
cParc1 Parameter for the 1st condition ('Y' or 'N')
nCond2 = Element for 2nd condition, according to position in the aPdV Matrix
cParc2 Parameter for the 2nd condition ("Y" or "N")
nMes If you wish to specify the payment month to be added.
Week =.[Link] all the weeks of the month. [Link] only the week of the calc.
aCodFol Matrix with calculation identifiers.

Example of Function for summation of funds, checking incidences

Total Income:

nTotProv:=0.00 -> Return variable of the total earnings


aEval(aPD,{|X| SomaInc(X,1,@nTotProv, , , , , , ,aCodFol})

Total Discounts

0.00
aEval(aPD,{|X| SomaInc(X,1,@nTotDesc, , , , , , ,aCodFol})

Liquid

nTotLiq:=0.00 -> [Link] of the Net amount


aEval(aPD,{|X| SomaInc(X,1,@nTotLiq, , , , , , ,aCodFol})
Created :
May 16, 2008
Creation of Calculation Scripts for the Payroll
Payment (SIGAGPE) Updated:
May 16, 2008

INSS base without 13th Salary

nInssBas:=0.00
aEval(aPD,{|X| SomaInc(X,4,@InssBas,12,"N", , , , ,aCodFol})

Base of Going without vacation and 13th Salary

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.

Example of Script to Return the Percentage of the Event:

nPerc:=PosSrv("114",SRA->RA_BRANCH,"RV_PERCENT")

Function to Search for a CFG Det. Param.

GETMV("MV_DIASMONTH")

Available Variables in Calculations:

aPd Array containing all the funds of the employee's movement.


aPdv Array with Incidents with the movement funds.
Val_SalMin Value of the minimum wage for the calculation month.
Normal = Hours of the Parameter Comp. of the Month or Work Shift
Rest Hours of the Parameter Comp. of the Month or Work Shift
nValArred Sheet Rounding Value
Val_Arre Rounding Value in the Adto
Val_Adto Value of the Advance
f_UltDia Last day of the Month
Salary Base Salary Month
Hello, friends Salary composed of the amounts that are incorporated
SalHour Composite Hourly Wage
SalDay Composite Daily Salary
nWorkingHours WorkedHours (Parameter for the Month or Work Shift)
Dsr Hours (Parameter Comp. of the Month or Work Shift)
DiasAfas Total Days Absent in the Month
nDaysSick Total Days of Illness in the Month
DaysInMonth Employee Vacation Days in the Month
nDaysMse Employee Vacation Days Next Month
Diastrab Employee Worked Days
DiasDsr Employee Dsr Days
cTipRes Type of Termination
will disregard the employee determined in the calculation
Created :
16/05/2008
Creation of Calculation Scripts for Payroll
Payment (SIGAGPE) Updated:
May 16, 2008

nFgtsCt1 Value of the percentage of FGTS for Unspecified Type Contract


Value of the FGTS percentage for Fixed-term Contracts
Payment Data Payment Date of the Payroll informed in the parameter.

. To include a RDMAKE in the scripts, inform in the true:


Execblock(NAME OF RDMAKE)

. To get an MV_........ parameter in SX6 to use in the script:


The Getmv(“MV_....”) function returns the content of the parameter for the script or rdmake.

Creating formula through SIGAGPE

Mnemonic

Access Updates / Calculation Definitions / 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:

Mnemonic Type Example of initialization


Character a
Numeric 250,00
Data 12/08/2002 or " / / "
Logical .T. (true) or .F. (false)
false)
Array (matrix/vector) {01,02,03,04}

Example: For the creation of Transfer Additional Formulas

About the fields:

Mnemonic Code - Enter a code that starts with 'M_'


Type - Choose the type of return that the formula will make, if it is for calculation scripts, in 90% of
cases will be numerical.
Created :
May 16, 2008
Creation of Calculation Scripts for the Payroll
Payment (SIGAGPE) Updated:
May 16, 2008

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

Access Updates / Calculation Definitions / Functions 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.)

Order Parameter Parameter Description


1st SRB Define the file to be searched
2nd 1 Determine the search order in the file
indicated
3rd SRA>RA_BRANCH+SRA>RA_M Indicate the search key in the file
AT indicated, in this case it will be researched
by the branch and enrollment of the employee
positioned in the file "SRA" (Registration
of Employees).
4th .F. Parameter to indicate the type of research
that is being carried out, if .F. (false)
indicates 1st. search in the file, if .T.
(True) indicates the selection of the next one
record with the same key.

In this example, the employee's dependents file being calculated is positioned. If


If there are dependents of this employee, it will return "true" and will remain positioned in
registration. Otherwise, it will return "false." If you want to check the existence of other records with the
same key, the function must be called again indicating ".T." in the last parameter.
The fields must be filled in according to the number of parameters defined previously.
for the function, that is, whoever creates the function, determines the number of parameters. The library only
stores these functions, and does not create new parameters or functions.
Created :
May 16, 2008
Creation of Calculation Scripts for the Payroll
Payment (SIGAGPE) Updated:
16/05/2008

Example: Function YearMonth

Formulas

Access Updates / Calculation Settings / 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.

The result of a formula will always be stored in a previously registered mnemonic.


in the routineMnemonic Registration.

Example: Additional Transfer Formula

Origin: This field is filled in by the system


Formula Code: Enter a preference code with the initials of the event to be calculated
Formula Description: Provide a brief description of the formula.
Return: Please provide the mnemonic registered for this formula
Note. Formula: Detail the entire process of this formula, this will help the customer or another analyst.
that comes to maintain this formula.

Items of the Formula


Created :
May 16, 2008
Creation of Calculation Scripts for the Payroll
Payment (SIGAGPE) Updated:
May 16, 2008

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

Click on the Expr. field and check the Condition option.

Click on the 1st Expression field

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,

if necessary, maintain this field. After click OK

Click on the Op.2 field (Operators)


Created :
May 16, 2008
Creation of Calculation Scripts for the Payroll
Payment (SIGAGPE) Updated:
May 16, 2008

Select the operation you wish. Then click OK.

Click on the 2nd Expression field

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

Click on the Op.3 field (Operators)


Created :
May 16, 2008
Creation of Calculation Scripts for the Payroll
Payment (SIGAGPE) Updated:
May 16, 2008

On the screen above, we chose the .END option because we will not have another condition, if that were the case.

we should choose the option .AND. . After clicking OK

Sequence 0020

Click on the Expr field.

We will choose the option above because we want not another condition but an execution.
After clicking OK

Click on the Result field to bring up the screen below.


Created :
16/05/2008
Creation of Calculation Scripts for the Payroll
Payment (SIGAGPE) Updated:
May 16, 2008

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,

if necessary, maintain this field. Then click OK

Click on the Op.3 field (Operators)


Created :
May 16, 2008
Creation of Calculation Scripts for the Payroll
Payment (SIGAGPE) Updated:
16/05/2008

On the screen above, we chose the option .END. because we will not have another execution, if that were the case.

we should choose the .CNT option. After that click OK

In the end, just click OK

Types used in the assembly of the Formulas

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.

Example 1 – Creating a formula to calculate a 10% bonus


about the employee's salary.
1 – Create a mnemonic to store this information:

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.

a) Creating the formula:


Created :
May 16, 2008
Creation of Calculation Scripts for the Payroll
Payment (SIGAGPE) Updated:
May 16, 2008

Detailing the formula:

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

3 - Embedding the formula created in the calculation script:

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.

4 - Calculate the payroll and verify the result


Created :
May 16, 2008
Creation of Calculation Scripts for the Payroll
Payment (SIGAGPE) Updated:
16/05/2008

Example 2 – Creating a formula to calculate a 10% commission


about the gratification of the previous example, being that it can only
appear for female employees (condition).

1 - Create the mnemonic

2 - Create the formula

Detailing the formula:


Line 1: condition to filter only employees with gender=F
Line 2: the variable receives the content of the gratification variable (previous example)
Line 3: used the Fgeraverba function to generate the item 229 (commission) retrieving the value of the variable
M_COMISS *= a 0.10

3 – Embed in the itinerary

4 - Calculate the payroll and verify the result


Created :
May 16, 2008
Creation of Calculation Scripts for the Payroll
Payment (SIGAGPE) Updated:
May 16, 2008

Example 3 - Creating a formula to calculate a 10% commission


about the gratification of the previous example, provided that it may only
appear for female employees (condition).

Exercise:

Develop a formula to calculate paid leave based on the


(non-working days / working days) * value of overtime hours +
commission
Non-working days - SR6->R6_HRDESC shift registration
Business days - SR6->R6_HRNORMA shift registration
Extra hours codes: 044 and 045
Commission words: 229
Words to pay the rest: 089

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

Example of a formula in ADVPL to calculate alimony


in a different way for an employee, function compiled and inserted in
script

#include "[Link]"

/*-----------------------------------------------------------------------*
Program 07/08/08
*------------------------------------------------------------------------*
Pension (HCM) *
*-----------------------------------------------------------------------*/
User Function RCFOL082()

Private nSalComp, nValPen

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()

Private nSalComp, nValPen

nSalComp := 0
nValPen := 0
nPert := .30

If SRA->RA_XPERC > 0 or SRA->RA_MAT = '000002'


nValPen := fSearchPD("101,103,105,402,410")
EndIf
nSalComp := (nValPen * nPert)
FGeraVerba("418", nSalComp,,,,,,,,,.T.)

Return

You might also like