As we know, while using an integration between SF Employee Central and SAP Employee Central Payroll the customers can face some "integration issues" due to standard validations that are made only at the ECP level, and not on EC (the core system).
One of these cases is about the PIS (Social Integration Program), a very relevant document for Brazilian customers. Once this document is registered on EC and integrated with ECP, ECP will validate if that document number is a valid number or not, while on EC the user can input any number sequence just like "9999" or "0000" for example. This would result in an integration error, that needs to be corrected on EC and reintegrated with ECP or by SLG1 transaction (ECP) or in the Monitor Job (EC).
Even if your customer doesn't have its payroll on ECP, it's always good to have the PIS being validated once filled in by the user.
So, just like CPF (our most common National id card in Brazil), the PIS has an Algorithm to define the range of 11 numeric characters and check if it's a valid combination or not.
The Algorithm
A)
Multiply each of the 10 first digits of the PIS for its weight
Digits : NNNNNNNNNN
Weights: 3, 2, 9, 8, 7, 6, 5, 4, 3, 2
It will be like this:
3 * N = X1
2 * N = X2
9 * N = X3
8 * N = X4
7 * N = X5
6 * N = X6
5 * N = X7
4 * N = X8
3 * N = X9
2 * N = X10
B)
Then you will have to sum the result of all these multiplications
Sum = X1 + X2 + X3 + X4 + X5 + X6 + X7 + X8 + X9 + X10
C)
The next step is to divide the result of the sum (B Item) by 11
Division = Sum / 11
D)
The last step will result in a Remainder. We will take this Remainder and subtract 11
Subtraction = Remainder of the C Item - 11
The result has to be equal to the last digit of the PIS so that this document can be considered a valid document
Business Rule
Ok, there is a logic. But how can we do this on the system?
To do that we will use our beautiful well-known Business Rules.
To translate that algorithm in a way that the system can validate the input number we will have to start our business rule from the end to the beginning of the algorithm. But how?
First of all, let's call the ‘Minus’ function
- Note that the first condition says that the type of document that must be checked is the “BRA – Social Integration Program” or PIS. -
Within the 'Minus' (1) function, we put '11' as the 'First Value' (2). The 'Second Value' must be the remainder of a Division just like we saw in step D of "The Algorithm" section.
Let’s now call the function ‘Modulo’ (3) which returns a remainder of a number divided by a divisor. We know that the ‘Divisor’ must be 11 (4), and the ‘Number’ has to be the result of a sum
(refer to step C of “The Algorithm” section). So we will call the function ‘Add Multiple’ as our ‘Number’ (5). It will look like this:
Now we will have to sum the result of 10 multiplications
(refer to steps A and B in “The Algorithm” section). We already have the ‘Add Multiple’ (1) that will be responsible for the sum. Now we will call the ‘Multiply’ function (2) so we can multiply digit by digit of our PIS, each one by its weight.
To do so, we have to use the 'Substring' (4) function, so we would be able to isolate each of the digits and multiply them. As we are not able to use this function yet, let's first use the function 'To number' (3), so then we can use the substring.
Within the ‘Substring’ function, first of all, we point to the field that will receive the PIS number (5). Then the ‘Start’ character (6) and the ‘Length’ (7), the quantity of digits that have to be considered in this substring
(in our use, this will be always 1).
Then we put the weight that has to multiply this specific digit, which for the first is 3.
Now repeat these last steps since the ‘Multiply’ function for each of the first 10 digits of the PIS
(refer to step A of “The Algorithm” section)
It will look like this:
Last but not least, we use the “not equal to” and isolate the last digit of the inserted PIS. Always when this algorithm is not matched with the last PIS digit, the rule will be triggered.
Then we put a polite message to say “No, this number is not a valid PIS number! Try it again” and make the field NULL.
Save your rule and put it as an 'onChange' event on the field level where the PIS will be inserted.
And that's it, I hope it helps.
Thanks!